From e7241a921407ae79e0767956127f7ed501c5eeb1 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Sun, 23 Jul 2017 19:52:14 -0700 Subject: Fixup for the glslang bug workaround There was a bug where the intialization expression for a variable was being lowered after the declaration was added to the output code, so that any sub-expressions that get hoisted out actually get computed *after* the original variable. This obviously led to downstream compilation failure. I've updated the test case to stress this scenario. --- source/slang/lower.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source/slang/lower.cpp') diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp index d634b114b..ba6b48509 100644 --- a/source/slang/lower.cpp +++ b/source/slang/lower.cpp @@ -3006,8 +3006,16 @@ return loweredExpr; } RefPtr loweredDecl = loweredDeclClass.createInstance(); + + // Note: we lower the declaration (including its initialization expression, if any) + // *before* we add the declaration to the current context (e.g., a statement being + // built), so that any operations inside the initialization expression that + // might need to inject statements/temporaries/whatever happen *before* + // the declaration of this variable. + auto result = lowerSimpleVarDeclCommon(loweredDecl, decl, loweredType); addDecl(loweredDecl); - return lowerSimpleVarDeclCommon(loweredDecl, decl, loweredType); + + return result; } RefPtr lowerVarDeclCommon( -- cgit v1.2.3