aprantl created this revision.

This patch fixes a regression introduced by r290392 
(https://reviews.llvm.org/D28047 — Make '-disable-llvm-optzns' an alias for 
'-disable-llvm-passes'.)

After r290392, CodeGenOpts.DisableLLVMOpts implicitly disables 
CodeGenOpts.VerifyModule, because the Verifier also happens to be implemented 
as an LLVM pass. This new behavior is undesirable because the Verifier is 
clearly not an optimization. One use-case where this is relevant is when using 
clang to compile bitcode; we don't want the compiler to crash on invalid input 
just because -disable-llvm-optzns is used.


https://reviews.llvm.org/D38042

Files:
  lib/CodeGen/BackendUtil.cpp
  test/CodeGen/verify-debuginfo.ll


Index: test/CodeGen/verify-debuginfo.ll
===================================================================
--- /dev/null
+++ test/CodeGen/verify-debuginfo.ll
@@ -0,0 +1,17 @@
+; REQUIRES: x86-registered-target
+; RUN: %clang_cc1 -triple i386-apple-darwin -disable-llvm-optzns -S %s -o - 
2>&1 \
+; RUN:   | FileCheck %s
+; CHECK: invalid global variable ref
+; CHECK: warning: ignoring invalid debug info in {{.*}}.ll
+
+@global = common global i32 0, align 4, !dbg !2
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: 
"adrian", emissionKind: FullDebug, globals: !{!3})
+!1 = !DIFile(filename: "broken.c", directory: "/")
+!2 = !DIGlobalVariableExpression(var: !3, expr: !DIExpression())
+!3 = !DIGlobalVariable(name: "g", scope: !0, file: !1, line: 1, type: !1, 
isLocal: false, isDefinition: true)
+!5 = !{i32 2, !"Dwarf Version", i32 4}
+!6 = !{i32 1, !"Debug Info Version", i32 3}
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -461,8 +461,16 @@
                                       legacy::FunctionPassManager &FPM) {
   // Handle disabling of all LLVM passes, where we want to preserve the
   // internal module before any optimization.
-  if (CodeGenOpts.DisableLLVMPasses)
+  if (CodeGenOpts.DisableLLVMPasses) {
+    if (CodeGenOpts.VerifyModule) {
+      ModulePassManager MPM;
+      MPM.addPass(VerifierPass(false));
+      ModuleAnalysisManager MAM;
+      MAM.registerPass([&] { return VerifierAnalysis(); });
+      MPM.run(*TheModule, MAM);
+    }
     return;
+  }
 
   // Figure out TargetLibraryInfo.  This needs to be added to MPM and FPM
   // manually (and not via PMBuilder), since some passes (eg. InstrProfiling)


Index: test/CodeGen/verify-debuginfo.ll
===================================================================
--- /dev/null
+++ test/CodeGen/verify-debuginfo.ll
@@ -0,0 +1,17 @@
+; REQUIRES: x86-registered-target
+; RUN: %clang_cc1 -triple i386-apple-darwin -disable-llvm-optzns -S %s -o - 2>&1 \
+; RUN:   | FileCheck %s
+; CHECK: invalid global variable ref
+; CHECK: warning: ignoring invalid debug info in {{.*}}.ll
+
+@global = common global i32 0, align 4, !dbg !2
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "adrian", emissionKind: FullDebug, globals: !{!3})
+!1 = !DIFile(filename: "broken.c", directory: "/")
+!2 = !DIGlobalVariableExpression(var: !3, expr: !DIExpression())
+!3 = !DIGlobalVariable(name: "g", scope: !0, file: !1, line: 1, type: !1, isLocal: false, isDefinition: true)
+!5 = !{i32 2, !"Dwarf Version", i32 4}
+!6 = !{i32 1, !"Debug Info Version", i32 3}
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -461,8 +461,16 @@
                                       legacy::FunctionPassManager &FPM) {
   // Handle disabling of all LLVM passes, where we want to preserve the
   // internal module before any optimization.
-  if (CodeGenOpts.DisableLLVMPasses)
+  if (CodeGenOpts.DisableLLVMPasses) {
+    if (CodeGenOpts.VerifyModule) {
+      ModulePassManager MPM;
+      MPM.addPass(VerifierPass(false));
+      ModuleAnalysisManager MAM;
+      MAM.registerPass([&] { return VerifierAnalysis(); });
+      MPM.run(*TheModule, MAM);
+    }
     return;
+  }
 
   // Figure out TargetLibraryInfo.  This needs to be added to MPM and FPM
   // manually (and not via PMBuilder), since some passes (eg. InstrProfiling)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to