r219974 - Sema: handle additional case of qualified types

Saleem Abdulrasool compnerd at compnerd.org
Thu Oct 16 15:42:53 PDT 2014


Author: compnerd
Date: Thu Oct 16 17:42:53 2014
New Revision: 219974

URL: http://llvm.org/viewvc/llvm-project?rev=219974&view=rev
Log:
Sema: handle additional case of qualified types

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.

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

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=219974&r1=219973&r2=219974&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Oct 16 17:42:53 2014
@@ -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);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=219974&r1=219973&r2=219974&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 16 17:42:53 2014
@@ -10414,8 +10414,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
         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));
       }

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=219974&r1=219973&r2=219974&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Oct 16 17:42:53 2014
@@ -2755,17 +2755,20 @@ bool LocalTypedefNameReferencer::VisitRe
 }
 }
 
+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)) {

Modified: cfe/trunk/test/SemaCXX/attributed-auto-deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attributed-auto-deduction.cpp?rev=219974&r1=219973&r2=219974&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attributed-auto-deduction.cpp (original)
+++ cfe/trunk/test/SemaCXX/attributed-auto-deduction.cpp Thu Oct 16 17:42:53 2014
@@ -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() ) ) ) ) { }
+





More information about the cfe-commits mailing list