<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Eric,<div class=""><br class=""></div><div class="">Sure, will update it soon.</div><div class=""><br class=""><div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div>Regards,<br class="">Shilei<br class=""></div></div>

</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Jan 20, 2021, at 12:10 AM, Eric Christopher <<a href="mailto:echristo@gmail.com" class="">echristo@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><a class="gmail_plusreply" id="plusReplyChip-1" href="mailto:tpopp@google.com" tabindex="-1">+Tres Popp</a> (FYI)<div class=""><br class=""></div><div class="">Hi Shilei,</div><div class=""><br class=""></div><div class="">The other openmp targets tests are all _cc1 tests. I don't think there's a reason for these to not also be cc1, would you mind updating this?</div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">-eric</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 19, 2021 at 2:22 PM Shilei Tian via llvm-branch-commits <<a href="mailto:llvm-branch-commits@lists.llvm.org" class="">llvm-branch-commits@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br class="">
Author: Shilei Tian<br class="">
Date: 2021-01-19T14:18:42-05:00<br class="">
New Revision: 82e537a9d28a2c18bd1637e2eac0e0af658ed829<br class="">
<br class="">
URL: <a href="https://github.com/llvm/llvm-project/commit/82e537a9d28a2c18bd1637e2eac0e0af658ed829" rel="noreferrer" target="_blank" class="">https://github.com/llvm/llvm-project/commit/82e537a9d28a2c18bd1637e2eac0e0af658ed829</a><br class="">
DIFF: <a href="https://github.com/llvm/llvm-project/commit/82e537a9d28a2c18bd1637e2eac0e0af658ed829.diff" rel="noreferrer" target="_blank" class="">https://github.com/llvm/llvm-project/commit/82e537a9d28a2c18bd1637e2eac0e0af658ed829.diff</a><br class="">
<br class="">
LOG: [Clang][OpenMP] Fixed an issue that clang crashed when compiling OpenMP program in device only mode without host IR<br class="">
<br class="">
D94745 rewrites the `deviceRTLs` using OpenMP and compiles it by directly<br class="">
calling the device compilation. `clang` crashes because entry in<br class="">
`OffloadEntriesDeviceGlobalVar` is unintialized. Current design supposes the<br class="">
device compilation can only be invoked after host compilation with the host IR<br class="">
such that `clang` can initialize `OffloadEntriesDeviceGlobalVar` from host IR.<br class="">
This avoids us using device compilation directly, especially when we only have<br class="">
code wrapped into `declare target` which are all device code. The same issue<br class="">
also exists for `OffloadEntriesInfoManager`.<br class="">
<br class="">
In this patch, we simply initialized an entry if it is not in the maps. Not sure<br class="">
we need an option to tell the device compiler that it is invoked standalone.<br class="">
<br class="">
Reviewed By: jdoerfert<br class="">
<br class="">
Differential Revision: <a href="https://reviews.llvm.org/D94871" rel="noreferrer" target="_blank" class="">https://reviews.llvm.org/D94871</a><br class="">
<br class="">
Added: <br class="">
    clang/test/OpenMP/declare_target_device_only_compilation.cpp<br class="">
<br class="">
Modified: <br class="">
    clang/lib/CodeGen/CGOpenMPRuntime.cpp<br class="">
<br class="">
Removed: <br class="">
<br class="">
<br class="">
<br class="">
################################################################################<br class="">
diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp<br class="">
index a3b24039365b..17fa56fb06c8 100644<br class="">
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp<br class="">
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp<br class="">
@@ -2941,16 +2941,12 @@ void CGOpenMPRuntime::OffloadEntriesInfoManagerTy::<br class="">
   // If we are emitting code for a target, the entry is already initialized,<br class="">
   // only has to be registered.<br class="">
   if (CGM.getLangOpts().OpenMPIsDevice) {<br class="">
-    if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum)) {<br class="">
-      unsigned DiagID = CGM.getDiags().getCustomDiagID(<br class="">
-          DiagnosticsEngine::Error,<br class="">
-          "Unable to find target region on line '%0' in the device code.");<br class="">
-      CGM.getDiags().Report(DiagID) << LineNum;<br class="">
-      return;<br class="">
-    }<br class="">
+    // This could happen if the device compilation is invoked standalone.<br class="">
+    if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum))<br class="">
+      initializeTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum,<br class="">
+                                      OffloadingEntriesNum);<br class="">
     auto &Entry =<br class="">
         OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum];<br class="">
-    assert(Entry.isValid() && "Entry not initialized!");<br class="">
     Entry.setAddress(Addr);<br class="">
     Entry.setID(ID);<br class="">
     Entry.setFlags(Flags);<br class="">
@@ -3017,9 +3013,10 @@ void CGOpenMPRuntime::OffloadEntriesInfoManagerTy::<br class="">
                                      OMPTargetGlobalVarEntryKind Flags,<br class="">
                                      llvm::GlobalValue::LinkageTypes Linkage) {<br class="">
   if (CGM.getLangOpts().OpenMPIsDevice) {<br class="">
+    // This could happen if the device compilation is invoked standalone.<br class="">
+    if (!hasDeviceGlobalVarEntryInfo(VarName))<br class="">
+      initializeDeviceGlobalVarEntryInfo(VarName, Flags, OffloadingEntriesNum);<br class="">
     auto &Entry = OffloadEntriesDeviceGlobalVar[VarName];<br class="">
-    assert(Entry.isValid() && Entry.getFlags() == Flags &&<br class="">
-           "Entry not initialized!");<br class="">
     assert((!Entry.getAddress() || Entry.getAddress() == Addr) &&<br class="">
            "Resetting with the new address.");<br class="">
     if (Entry.getAddress() && hasDeviceGlobalVarEntryInfo(VarName)) {<br class="">
<br class="">
diff  --git a/clang/test/OpenMP/declare_target_device_only_compilation.cpp b/clang/test/OpenMP/declare_target_device_only_compilation.cpp<br class="">
new file mode 100644<br class="">
index 000000000000..280959540306<br class="">
--- /dev/null<br class="">
+++ b/clang/test/OpenMP/declare_target_device_only_compilation.cpp<br class="">
@@ -0,0 +1,15 @@<br class="">
+//==========================================================================///<br class="">
+// RUN: %clang -S -target powerpc64le-ibm-linux-gnu -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s<br class="">
+// RUN: %clang -S -target i386-pc-linux-gnu -fopenmp -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s<br class="">
+// RUN: %clang -S -target x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s<br class="">
+// expected-no-diagnostics<br class="">
+<br class="">
+#pragma omp declare target<br class="">
+#pragma omp begin declare variant match(device={kind(nohost)})<br class="">
+int G1;<br class="">
+#pragma omp end declare variant<br class="">
+#pragma omp end declare target<br class="">
+<br class="">
+// CHECK: @[[G:.+]] = hidden {{.*}}global i32 0, align 4<br class="">
+// CHECK: !<a href="http://omp_offload.info/" rel="noreferrer" target="_blank" class="">omp_offload.info</a> = !{!0}<br class="">
+// CHECK: !0 = !{i32 1, !"[[G]]", i32 0, i32 0}<br class="">
<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-branch-commits mailing list<br class="">
<a href="mailto:llvm-branch-commits@lists.llvm.org" target="_blank" class="">llvm-branch-commits@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>