Author: Shilei Tian Date: 2023-01-20T14:40:24-05:00 New Revision: 2ebda47619d7e8b72d460a955de4f398f637489f
URL: https://github.com/llvm/llvm-project/commit/2ebda47619d7e8b72d460a955de4f398f637489f DIFF: https://github.com/llvm/llvm-project/commit/2ebda47619d7e8b72d460a955de4f398f637489f.diff LOG: [Clang][OpenMP] Bail out early if `Scope` is nullptr in case of any crash 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. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D142233 Added: clang/test/OpenMP/bug59944.c Modified: clang/lib/Sema/SemaOpenMP.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 97eba46b5a4f..1b9d06b671b8 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -7259,7 +7259,7 @@ ExprResult Sema::ActOnOpenMPCall(ExprResult Call, Scope *Scope, if (LangOpts.OpenMP >= 51 && CalleeFnDecl->getIdentifier() && CalleeFnDecl->getName().startswith_insensitive("omp_")) { // checking for any calls inside an Order region - if (Scope->isOpenMPOrderClauseScope()) + if (Scope && Scope->isOpenMPOrderClauseScope()) Diag(LParenLoc, diag::err_omp_unexpected_call_to_omp_runtime_api); } diff --git a/clang/test/OpenMP/bug59944.c b/clang/test/OpenMP/bug59944.c new file mode 100644 index 000000000000..6d061b51d505 --- /dev/null +++ b/clang/test/OpenMP/bug59944.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c -triple x86_64-apple-darwin10 %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK + +extern int omp_get_initial_device(); +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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits