2
0
Эх сурвалжийг харах

[spirv] Stop if errors happen during translating Decls (#701)

This prevents us from calling legalization/optimization passes
on invalid SPIR-V binary code.
Lei Zhang 8 жил өмнө
parent
commit
2419dbba86

+ 9 - 6
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -255,12 +255,6 @@ void SPIRVEmitter::HandleTranslationUnit(ASTContext &context) {
   if (context.getDiagnostics().hasErrorOccurred())
     return;
 
-  AddRequiredCapabilitiesForShaderModel();
-
-  // Addressing and memory model are required in a valid SPIR-V module.
-  theBuilder.setAddressingModel(spv::AddressingModel::Logical);
-  theBuilder.setMemoryModel(spv::MemoryModel::GLSL450);
-
   TranslationUnitDecl *tu = context.getTranslationUnitDecl();
 
   // The entry function is the seed of the queue.
@@ -292,6 +286,15 @@ void SPIRVEmitter::HandleTranslationUnit(ASTContext &context) {
     doDecl(workQueue[i]);
   }
 
+  if (context.getDiagnostics().hasErrorOccurred())
+    return;
+
+  AddRequiredCapabilitiesForShaderModel();
+
+  // Addressing and memory model are required in a valid SPIR-V module.
+  theBuilder.setAddressingModel(spv::AddressingModel::Logical);
+  theBuilder.setMemoryModel(spv::MemoryModel::GLSL450);
+
   theBuilder.addEntryPoint(getSpirvShaderStage(shaderModel), entryFunctionId,
                            entryFunctionName, declIdMapper.collectStageVars());