[OpenMP][FIX] Emit debug declares only if debug info is available
authorJohannes Doerfert <johannes@jdoerfert.de>
Sat, 8 Jan 2022 19:53:39 +0000 (13:53 -0600)
committerJohannes Doerfert <johannes@jdoerfert.de>
Sat, 8 Jan 2022 23:01:19 +0000 (17:01 -0600)
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

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

index 9447266..b340e05 100644 (file)
@@ -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.
index a68e1d1..f25b458 100644 (file)
@@ -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"
index c3a23bc..941d31e 100644 (file)
@@ -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.