Skip to content

Commit

Permalink
Mark reducer callbacks used when the type is instantiated
Browse files Browse the repository at this point in the history
  • Loading branch information
VoxSciurorum committed Aug 26, 2024
1 parent 66a8741 commit 492d55b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2406,8 +2406,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<DeclRefExpr>(E))
cast<DeclRefExpr>(E)->getDecl()->markUsed(Context);
} else {
E = new (Context) CXXNullPtrLiteralExpr(Context.NullPtrTy, Loc);
}

QualType T = E->getType();

Expand Down
17 changes: 17 additions & 0 deletions clang/test/Cilk/154.cpp
Original file line number Diff line number Diff line change
@@ -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 <class T>
T sum_cilk(){
long _Hyperobject(identity_64, sum_64) sum = 0;
return sum;
}

long f() {
long total = sum_cilk<long>();
return total;
}

0 comments on commit 492d55b

Please sign in to comment.