[cfe-commits] r139373 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaTemplate/atomics.cpp
Douglas Gregor
dgregor at apple.com
Fri Sep 9 09:51:10 PDT 2011
Author: dgregor
Date: Fri Sep 9 11:51:10 2011
New Revision: 139373
URL: http://llvm.org/viewvc/llvm-project?rev=139373&view=rev
Log:
When type-checking a call to an overloaded, builtin atomic operation,
construct a new DeclRefExpr rather than re-using the existing
DeclRefExpr. Patch by Likai Liu, fixes PR8345.
Added:
cfe/trunk/test/SemaTemplate/atomics.cpp
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=139373&r1=139372&r2=139373&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Sep 9 11:51:10 2011
@@ -614,13 +614,20 @@
TheCall->setArg(i+1, Arg.get());
}
- // Switch the DeclRefExpr to refer to the new decl.
- DRE->setDecl(NewBuiltinDecl);
- DRE->setType(NewBuiltinDecl->getType());
+ ASTContext& Context = this->getASTContext();
+
+ // Create a new DeclRefExpr to refer to the new decl.
+ DeclRefExpr* NewDRE = DeclRefExpr::Create(
+ Context,
+ DRE->getQualifierLoc(),
+ NewBuiltinDecl,
+ DRE->getLocation(),
+ NewBuiltinDecl->getType(),
+ DRE->getValueKind());
// Set the callee in the CallExpr.
// FIXME: This leaks the original parens and implicit casts.
- ExprResult PromotedCall = UsualUnaryConversions(DRE);
+ ExprResult PromotedCall = UsualUnaryConversions(NewDRE);
if (PromotedCall.isInvalid())
return ExprError();
TheCall->setCallee(PromotedCall.take());
Added: cfe/trunk/test/SemaTemplate/atomics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/atomics.cpp?rev=139373&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/atomics.cpp (added)
+++ cfe/trunk/test/SemaTemplate/atomics.cpp Fri Sep 9 11:51:10 2011
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR8345
+template<typename T> T f(T* value) {
+ return __sync_add_and_fetch(value, 1);
+}
+int g(long long* x) { return f(x); }
+int g(int* x) { return f(x); }
More information about the cfe-commits
mailing list