[PATCH] D142233: [Clang][OpenMP] Bail out early if `Scope` is nullptr in case of any crash

Shilei Tian via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 20 09:32:21 PST 2023


tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, ABataev, sandeepkosuri, cchen, jyu2.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

When there is any compile error, clang still tries to compile as many code as
possible, therefore `Scope` can be `nullptr` here. However, we didn't check it
beforehand, causing compiler crash.

Fix #59944.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142233

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/bug59944.c


Index: clang/test/OpenMP/bug59944.c
===================================================================
--- /dev/null
+++ clang/test/OpenMP/bug59944.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c -triple x86_64-apple-darwin10 %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK
+
+extern void *omp_get_mapped_ptr(void *, int);
+
+void t() {
+  omp_get_mapped_ptr(&x, omp_get_initial_device());
+}
+
+// CHECK: error: use of undeclared identifier 'x'
+// CHECK-NOT: crash
Index: clang/lib/Sema/SemaOpenMP.cpp
===================================================================
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -7239,6 +7239,10 @@
   if (!CalleeFnDecl)
     return Call;
 
+  // Scope can be nullptr here if any compile error is encountered before.
+  if (!Scope)
+    return Call;
+
   if (LangOpts.OpenMP >= 51 && CalleeFnDecl->getIdentifier() &&
       CalleeFnDecl->getName().startswith_insensitive("omp_")) {
     // checking for any calls inside an Order region


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142233.490894.patch
Type: text/x-patch
Size: 1027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230120/fc5a4c3f/attachment-0001.bin>


More information about the cfe-commits mailing list