浏览代码

[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 年之前
父节点
当前提交
2419dbba86
共有 1 个文件被更改,包括 9 次插入6 次删除
  1. 9 6
      tools/clang/lib/SPIRV/SPIRVEmitter.cpp

+ 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());