[clang] 37639b7 - [OpenMP][FIX] Emit debug declares only if debug info is available

Johannes Doerfert via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 8 16:13:35 PST 2022


Author: Johannes Doerfert
Date: 2022-01-08T17:01:19-06:00
New Revision: 37639b72a17be443e7f73e906554f8bbd0dbf271

URL: https://github.com/llvm/llvm-project/commit/37639b72a17be443e7f73e906554f8bbd0dbf271
DIFF: https://github.com/llvm/llvm-project/commit/37639b72a17be443e7f73e906554f8bbd0dbf271.diff

LOG: [OpenMP][FIX] Emit debug declares only if debug info is available

The `EmitDeclareOfAutoVariable` introduced in D114504 and D115510 has a
precondition that cannot be violated. It is unclear if we should call it
directly given the sparse usage in clang but for now we should at least
not crash if the debug info kind is too low.

Fixes #52938.

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

Added: 
    

Modified: 
    clang/lib/CodeGen/CGStmtOpenMP.cpp
    clang/test/OpenMP/debug_private.c
    clang/test/OpenMP/debug_task_shared.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 94472668c8e70..b340e0505a788 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4460,8 +4460,9 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
               CGF.getContext().getASTRecordLayout(CaptureRecord);
           unsigned Offset =
               Layout.getFieldOffset(It->second->getFieldIndex()) / CharWidth;
-          (void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
-                                              CGF.Builder, false);
+          if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+            (void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
+                                                CGF.Builder, false);
           llvm::Instruction &Last = CGF.Builder.GetInsertBlock()->back();
           // Get the call dbg.declare instruction we just created and update
           // its DIExpression to add offset to base address.
@@ -4560,8 +4561,10 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
                             CGF.getContext().getDeclAlign(Pair.first));
         Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
         if (auto *DI = CGF.getDebugInfo())
-          DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
-                                        CGF.Builder, /*UsePointerValue*/ true);
+          if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
+            (void)DI->EmitDeclareOfAutoVariable(
+                Pair.first, Pair.second.getPointer(), CGF.Builder,
+                /*UsePointerValue*/ true);
       }
       // Adjust mapping for internal locals by mapping actual memory instead of
       // a pointer to this memory.

diff  --git a/clang/test/OpenMP/debug_private.c b/clang/test/OpenMP/debug_private.c
index a68e1d1be7526..f25b45855b112 100644
--- a/clang/test/OpenMP/debug_private.c
+++ b/clang/test/OpenMP/debug_private.c
@@ -4,6 +4,9 @@
 // REQUIRES: x86_64-linux
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
 // expected-no-diagnostics
 
 // CHECK: define internal i32 @.omp_task_entry.
@@ -11,6 +14,7 @@
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 // CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// NEG-NOT: call void @llvm.dbg.declare
 
 // CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
 // CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"

diff  --git a/clang/test/OpenMP/debug_task_shared.c b/clang/test/OpenMP/debug_task_shared.c
index c3a23bc486324..941d31eead3c9 100644
--- a/clang/test/OpenMP/debug_task_shared.c
+++ b/clang/test/OpenMP/debug_task_shared.c
@@ -5,6 +5,9 @@
 
 // RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
 // RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-directives-only -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=line-tables-only -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
+// RUN: %clang_cc1 -debug-info-kind=limited -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
 // expected-no-diagnostics
 
 // CHECK-LABEL: define internal i32 @.omp_task_entry.


        


More information about the cfe-commits mailing list