From 23c49630543c9e76d609463a1cb0dffcdef2c77b Mon Sep 17 00:00:00 2001 From: "John F. Carr" Date: Wed, 3 Jan 2024 10:01:39 -0500 Subject: [PATCH] Mark reducer callbacks used when the type is instantiated --- clang/lib/Sema/SemaType.cpp | 6 +++++- clang/test/Cilk/154.cpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 clang/test/Cilk/154.cpp diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index e4b9c77abacf..ae2696a35264 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2362,8 +2362,12 @@ QualType Sema::BuildReferenceType(QualType T, bool SpelledAsLValue, // Return value is always non-null. Expr *Sema::ValidateReducerCallback(Expr *E, unsigned NumArgs, SourceLocation Loc) { - if (!E) + if (E) { + if (!E->getType()->isDependentType() && isa(E)) + cast(E)->getDecl()->markUsed(Context); + } else { E = new (Context) CXXNullPtrLiteralExpr(Context.NullPtrTy, Loc); + } QualType T = E->getType(); diff --git a/clang/test/Cilk/154.cpp b/clang/test/Cilk/154.cpp new file mode 100644 index 000000000000..f11a8f95c968 --- /dev/null +++ b/clang/test/Cilk/154.cpp @@ -0,0 +1,17 @@ +// Bug 154: Spurious "not needed" warnings for reducer callbacks with -Wall. +// RUN: %clang_cc1 %s -x c++ -fopencilk -fsyntax-only -Wall -verify +// expected-no-diagnostics + +static void identity_64(void *p) { *(long *)p = 0; } +static void sum_64(void *l, void *r) { *(long *)l += *(long *)r; } + +template +T sum_cilk(){ + long _Hyperobject(identity_64, sum_64) sum = 0; + return sum; +} + +long f() { + long total = sum_cilk(); + return total; +}