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


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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to