[PATCH] D94871: [Clang][OpenMP] Fixed an issue that clang crashed when compiling OpenMP program in device only mode without host IR

Shilei Tian via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 18 18:36:11 PST 2021


tianshilei1992 updated this revision to Diff 317444.
tianshilei1992 added a comment.

Removed the useless assertion


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94871/new/

https://reviews.llvm.org/D94871

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_target_device_only_compilation.cpp


Index: clang/test/OpenMP/declare_target_device_only_compilation.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/declare_target_device_only_compilation.cpp
@@ -0,0 +1,15 @@
+//==========================================================================///
+// RUN: %clang -S -target powerpc64le-ibm-linux-gnu -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang -S -target i386-pc-linux-gnu -fopenmp -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang -S -target x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#pragma omp declare target
+#pragma omp begin declare variant match(device={kind(nohost)})
+int G1;
+#pragma omp end declare variant
+#pragma omp end declare target
+
+// CHECK: @[[G:.+]] = hidden {{.*}}global i32 0, align 4
+// CHECK: !omp_offload.info = !{!0}
+// CHECK: !0 = !{i32 1, !"[[G]]", i32 0, i32 0}
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2941,16 +2941,12 @@
   // If we are emitting code for a target, the entry is already initialized,
   // only has to be registered.
   if (CGM.getLangOpts().OpenMPIsDevice) {
-    if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum)) {
-      unsigned DiagID = CGM.getDiags().getCustomDiagID(
-          DiagnosticsEngine::Error,
-          "Unable to find target region on line '%0' in the device code.");
-      CGM.getDiags().Report(DiagID) << LineNum;
-      return;
-    }
+    // This could happen if the device compilation is invoked standalone.
+    if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum))
+      initializeTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum,
+                                      OffloadingEntriesNum);
     auto &Entry =
         OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum];
-    assert(Entry.isValid() && "Entry not initialized!");
     Entry.setAddress(Addr);
     Entry.setID(ID);
     Entry.setFlags(Flags);
@@ -3017,9 +3013,10 @@
                                      OMPTargetGlobalVarEntryKind Flags,
                                      llvm::GlobalValue::LinkageTypes Linkage) {
   if (CGM.getLangOpts().OpenMPIsDevice) {
+    // This could happen if the device compilation is invoked standalone.
+    if (!hasDeviceGlobalVarEntryInfo(VarName))
+      initializeDeviceGlobalVarEntryInfo(VarName, Flags, OffloadingEntriesNum);
     auto &Entry = OffloadEntriesDeviceGlobalVar[VarName];
-    assert(Entry.isValid() && Entry.getFlags() == Flags &&
-           "Entry not initialized!");
     assert((!Entry.getAddress() || Entry.getAddress() == Addr) &&
            "Resetting with the new address.");
     if (Entry.getAddress() && hasDeviceGlobalVarEntryInfo(VarName)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94871.317444.patch
Type: text/x-patch
Size: 3038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210119/b4eda729/attachment-0001.bin>


More information about the cfe-commits mailing list