Author: Yaxun (Sam) Liu Date: 2020-05-21T11:01:40-04:00 New Revision: 3ef11346f391e6e3da0cfa25f9f7dac22771438e
URL: https://github.com/llvm/llvm-project/commit/3ef11346f391e6e3da0cfa25f9f7dac22771438e DIFF: https://github.com/llvm/llvm-project/commit/3ef11346f391e6e3da0cfa25f9f7dac22771438e.diff LOG: Fix DeferredDiagnosticsEmitter for bug#45987 InOMPDeviceContext may be greater than 1. It needs to be clamp to 0 and 1 to be used as index for DoneMap. Added: clang/test/OpenMP/deferred-diags.cpp Modified: clang/lib/Sema/Sema.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 0d2877efe3ee..b3aeb1018467 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -1539,7 +1539,7 @@ class DeferredDiagnosticsEmitter } void checkFunc(SourceLocation Loc, FunctionDecl *FD) { - auto &Done = DoneMap[InOMPDeviceContext]; + auto &Done = DoneMap[InOMPDeviceContext > 0 ? 1 : 0]; FunctionDecl *Caller = UsePath.empty() ? nullptr : UsePath.back(); if ((!ShouldEmitRootNode && !S.getLangOpts().OpenMP && !Caller) || S.shouldIgnoreInHostDeviceCheck(FD) || InUsePath.count(FD)) diff --git a/clang/test/OpenMP/deferred-diags.cpp b/clang/test/OpenMP/deferred-diags.cpp new file mode 100644 index 000000000000..98c28aff644a --- /dev/null +++ b/clang/test/OpenMP/deferred-diags.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -triple x86_64 -verify=expected,dev -std=c++11\ +// RUN: -verify-ignore-unexpected=note \ +// RUN: -fopenmp -fopenmp-version=50 -o - %s + +// expected-no-diagnostics + +// Test no infinite recursion in DeferredDiagnosticEmitter. +constexpr int foo(int *x) { + return 0; +} + +int a = foo(&a); + +// Test no crash when both caller and callee have target directives. +int foo(); + +class B { +public: + void barB(int *isHost) { + #pragma omp target map(tofrom: isHost) + { + *isHost = foo(); + } + } +}; + +class A : public B { +public: + void barA(int *isHost) { + #pragma omp target map(tofrom: isHost) + { + barB(isHost); + } + } +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits