]> granicus.if.org Git - clang/commitdiff
When type-checking a call to an overloaded, builtin atomic operation,
authorDouglas Gregor <dgregor@apple.com>
Fri, 9 Sep 2011 16:51:10 +0000 (16:51 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 9 Sep 2011 16:51:10 +0000 (16:51 +0000)
construct a new DeclRefExpr rather than re-using the existing
DeclRefExpr. Patch by Likai Liu, fixes PR8345.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139373 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/SemaTemplate/atomics.cpp [new file with mode: 0644]

index b1a87a83dcebdd815cf6325585d38f4a315b36df..68e25e7f4e5a48e218fac37c74c0ff58cdb7656b 100644 (file)
@@ -614,13 +614,20 @@ Sema::SemaBuiltinAtomicOverloaded(ExprResult TheCallResult) {
     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());
diff --git a/test/SemaTemplate/atomics.cpp b/test/SemaTemplate/atomics.cpp
new file mode 100644 (file)
index 0000000..7165bbe
--- /dev/null
@@ -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); }