]> granicus.if.org Git - clang/commitdiff
Sema: handle additional case of qualified types
authorSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 16 Oct 2014 22:42:53 +0000 (22:42 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 16 Oct 2014 22:42:53 +0000 (22:42 +0000)
A second instance of attributed types escaped the previous change, identified
thanks to Richard Smith!  When deducing the void case, we would also assume that
the type would not be attributed.  Furthermore, properly handle multiple
attributes being applied to a single TypeLoc.

Properly handle this case and future-proof a bit by ignoring parenthesis
further.  The test cases do use the additional parenthesis to ensure that this
case remains properly handled.

Addresses post-commit review comments from Richard Smith to SVN r219851.

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

include/clang/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaStmt.cpp
test/SemaCXX/attributed-auto-deduction.cpp

index f4579c2c3fade524d5eb5b368ee58bd45150781a..372365452ecf78b53820d11cee458c79b610c84f 100644 (file)
@@ -6104,6 +6104,8 @@ public:
   bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc,
                         bool Diagnose = true);
 
+  TypeLoc getReturnTypeLoc(FunctionDecl *FD) const;
+
   bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
                                         SourceLocation ReturnLoc,
                                         Expr *&RetExpr, AutoType *AT);
index 6f20c6a9f78202cb7817ef57788bf20e5455dacc..31266355e52fa896c1421aa5b41d1d06970c4687 100644 (file)
@@ -10414,8 +10414,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
         FD->setInvalidDecl();
       } else {
         // Substitute 'void' for the 'auto' in the type.
-        TypeLoc ResultType = FD->getTypeSourceInfo()->getTypeLoc().
-            IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();
+        TypeLoc ResultType = getReturnTypeLoc(FD);
         Context.adjustDeducedFunctionResultType(
             FD, SubstAutoType(ResultType.getType(), Context.VoidTy));
       }
index 7efcb2e9c49d4a6b46aea31350045b27af311395..8a28b29a1cabc1be32f9eb846ac4f5297aa778a0 100644 (file)
@@ -2755,17 +2755,20 @@ bool LocalTypedefNameReferencer::VisitRecordType(const RecordType *RT) {
 }
 }
 
+TypeLoc Sema::getReturnTypeLoc(FunctionDecl *FD) const {
+  TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
+  while (auto ATL = TL.getAs<AttributedTypeLoc>())
+    TL = ATL.getModifiedLoc().IgnoreParens();
+  return TL.IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();
+}
+
 /// Deduce the return type for a function from a returned expression, per
 /// C++1y [dcl.spec.auto]p6.
 bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
                                             SourceLocation ReturnLoc,
                                             Expr *&RetExpr,
                                             AutoType *AT) {
-  TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
-  if (auto ATL = TL.getAs<AttributedTypeLoc>())
-    TL = ATL.getModifiedLoc();
-  TypeLoc OrigResultType =
-      TL.IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();
+  TypeLoc OrigResultType = getReturnTypeLoc(FD);
   QualType Deduced;
 
   if (RetExpr && isa<InitListExpr>(RetExpr)) {
index d8dc43d66918c264bb94064b7dce1f46926ef428..b0cae187e8e3138210e111304d1ef42caecd58c7 100644 (file)
@@ -2,9 +2,19 @@
 // expected-no-diagnostics
 
 void deduce() {
-  auto lambda = [](int i) __attribute__ (( pcs("aapcs") )) {
+  auto single_int = [](int i) __attribute__ (( pcs("aapcs") )) {
     return i;
   };
-  lambda(42);
+  auto multiple_int = [](int i) __attribute__ (( pcs("aapcs") ))
+                                __attribute__ (( pcs("aapcs") )) {
+    return i;
+  };
+
+  auto single_void = []() __attribute__ (( pcs("aapcs") )) { };
+  auto multiple_void = []() __attribute__ (( pcs("aapcs") ))
+                            __attribute__ (( pcs("aapcs") )) { };
 }
 
+auto ( __attribute__ (( pcs("aapcs") )) single_attribute() ) { }
+auto ( ( __attribute__ (( pcs("aapcs") )) ( ( __attribute__ (( pcs("aapcs") )) multiple_attributes() ) ) ) ) { }
+