Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark reducer callbacks used when the type is instantiated #228

Draft
wants to merge 1 commit into
base: dev/18.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}