[clang] [DebugInfo] Correct the line attribution for IF branches (PR #108300)

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 12 16:42:15 PDT 2024


================
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -gno-column-info -triple=x86_64-pc-linux -emit-llvm %s -o - | FileCheck  %s
+
+// The important thing is that the compare and the conditional branch have
+// locs with the same scope (the lexical block for the 'if'). By turning off
+// column info, they end up with the same !dbg record, which halves the number
+// of checks to verify the scope.
+
+int c = 2;
+
+int f() {
+#line 100
+  if (int a = 5; a > c)
+    return 1;
+  return 0;
+}
+// CHECK-LABEL: define {{.*}} @_Z1fv()
+// CHECK:       = icmp {{.*}} !dbg [[F_CMP:![0-9]+]]
+// CHECK-NEXT:  br i1 {{.*}} !dbg [[F_CMP]]
----------------
dwblaikie wrote:

Hmm, yeah, that `EmitStopPoint` seems a bit unstable/unreliable - the scoped location handling is designed to be more robust to ensure locations don't "leak out" beyond where they're meant to apply... 

I think maybe `EmitStopPoint` should be removed/reconsidered, but that's perhaps beyond the scope (har har) of this issue - but thoughts in case anyone else feels like picking up and running with that.

How's this location compare to other control structures (loops, etc) - do we (& GCC) use the condition as the location for the branch instructions, or would it be more suitable to use the start of `if` itself?

https://github.com/llvm/llvm-project/pull/108300


More information about the cfe-commits mailing list