[clang] 13a044c - [DebugInfo] Fix incorrect dbg.declare when nrvo flag is used

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 29 02:40:07 PDT 2023


Author: Nikita Popov
Date: 2023-08-29T11:39:59+02:00
New Revision: 13a044c6993a914fc33549b72215e698a1cdef63

URL: https://github.com/llvm/llvm-project/commit/13a044c6993a914fc33549b72215e698a1cdef63
DIFF: https://github.com/llvm/llvm-project/commit/13a044c6993a914fc33549b72215e698a1cdef63.diff

LOG: [DebugInfo] Fix incorrect dbg.declare when nrvo flag is used

When clang generates an nrvo boolean flag, the dbg.declare for the
corresponding variable was incorrectly placed on that flag, rather
than the actual variable.

Fix this by not overwriting AllocaAddr with the nrvo flag.

This started causing verifier errors with D158743.

Differential Revision: https://reviews.llvm.org/D158972

Added: 
    clang/test/CodeGenCXX/trivial_abi_debuginfo.cpp

Modified: 
    clang/lib/CodeGen/CGDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index d8f2fa1f593a60..99b94588f56f0a 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1534,8 +1534,7 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
           // applied.
           llvm::Value *Zero = Builder.getFalse();
           Address NRVOFlag =
-              CreateTempAlloca(Zero->getType(), CharUnits::One(), "nrvo",
-                               /*ArraySize=*/nullptr, &AllocaAddr);
+              CreateTempAlloca(Zero->getType(), CharUnits::One(), "nrvo");
           EnsureInsertPoint();
           Builder.CreateStore(Zero, NRVOFlag);
 

diff  --git a/clang/test/CodeGenCXX/trivial_abi_debuginfo.cpp b/clang/test/CodeGenCXX/trivial_abi_debuginfo.cpp
new file mode 100644
index 00000000000000..3d93f20ee1b242
--- /dev/null
+++ b/clang/test/CodeGenCXX/trivial_abi_debuginfo.cpp
@@ -0,0 +1,33 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --functions "makeTrivial" --version 2
+// RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+struct __attribute__((trivial_abi)) Trivial {
+  ~Trivial() {}
+  int ivar = 10;
+};
+
+// The dbg.declare should be on %retval, not on %nrvo.
+
+// CHECK-LABEL: define dso_local i32 @_Z11makeTrivialv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] !dbg [[DBG5:![0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[RETVAL:%.*]] = alloca [[STRUCT_TRIVIAL:%.*]], align 4
+// CHECK-NEXT:    [[NRVO:%.*]] = alloca i1, align 1
+// CHECK-NEXT:    store i1 false, ptr [[NRVO]], align 1, !dbg [[DBG18:![0-9]+]]
+// CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[RETVAL]], metadata [[META19:![0-9]+]], metadata !DIExpression()), !dbg [[DBG20:![0-9]+]]
+// CHECK-NEXT:    call void @_ZN7TrivialC1Ev(ptr noundef nonnull align 4 dereferenceable(4) [[RETVAL]]) #[[ATTR3:[0-9]+]], !dbg [[DBG20]]
+// CHECK-NEXT:    store i1 true, ptr [[NRVO]], align 1, !dbg [[DBG21:![0-9]+]]
+// CHECK-NEXT:    [[NRVO_VAL:%.*]] = load i1, ptr [[NRVO]], align 1, !dbg [[DBG22:![0-9]+]]
+// CHECK-NEXT:    br i1 [[NRVO_VAL]], label [[NRVO_SKIPDTOR:%.*]], label [[NRVO_UNUSED:%.*]], !dbg [[DBG22]]
+// CHECK:       nrvo.unused:
+// CHECK-NEXT:    call void @_ZN7TrivialD1Ev(ptr noundef nonnull align 4 dereferenceable(4) [[RETVAL]]) #[[ATTR3]], !dbg [[DBG22]]
+// CHECK-NEXT:    br label [[NRVO_SKIPDTOR]], !dbg [[DBG22]]
+// CHECK:       nrvo.skipdtor:
+// CHECK-NEXT:    [[COERCE_DIVE:%.*]] = getelementptr inbounds [[STRUCT_TRIVIAL]], ptr [[RETVAL]], i32 0, i32 0, !dbg [[DBG22]]
+// CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[COERCE_DIVE]], align 4, !dbg [[DBG22]]
+// CHECK-NEXT:    ret i32 [[TMP0]], !dbg [[DBG22]]
+//
+Trivial makeTrivial() {
+  Trivial ret_val;
+  return ret_val;
+}


        


More information about the cfe-commits mailing list