[PATCH] [AST] Introduce a new DecayedType sugar node
Reid Kleckner
rnk at google.com
Fri Jun 21 10:07:47 PDT 2013
================
Comment at: lib/Sema/SemaType.cpp:3576-3578
@@ -3579,2 +3575,5 @@
}
+ void VisitDecayedTypeLoc(DecayedTypeLoc TL) {
+ llvm_unreachable("decayed type locs not expected here!");
+ }
----------------
Richard Smith wrote:
> How do we ever fill in a DecayedTypeLoc's inner type?
Decayed types are never returned by GetTypeForDeclarator(), so we never call DeclaratorLocFiller on it. Alternatively I can make it do nothing, but it's dead code.
================
Comment at: lib/Serialization/ASTReader.cpp:4523-4526
@@ +4522,6 @@
+ QualType OriginalType = readType(*Loc.F, Record, Idx);
+ QualType DT = Context.getMaybeDecayedType(OriginalType);
+ if (!isa<DecayedType>(DT))
+ Error("Decayed type does not decay");
+ return DT;
+ }
----------------
Richard Smith wrote:
> This is just 'return Context.getDecayedType(OriginalType);', right?
The difference is that this doesn't assert, it calls Error() and tries to recover.
================
Comment at: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp:599-602
@@ -598,5 +598,6 @@
if (FTP->getNumArgs() == 1) {
- // Is the argument an 'unsigned short *'?
+ // Is the canonical argument type 'unsigned short *'?
// (Actually any integer type is allowed.)
- const PointerType *PT = dyn_cast<PointerType>(FTP->getArgType(0));
+ const PointerType *PT =
+ dyn_cast<PointerType>(FTP->getArgType(0).getCanonicalType());
if (!PT)
----------------
Richard Smith wrote:
> This should be replaced with FTP->getArgType(0)->getAs<PointerType>().
Done here and elsewhere.
================
Comment at: tools/libclang/CIndex.cpp:1550-1553
@@ +1549,6 @@
+bool CursorVisitor::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
+ if (Visit(TL.getOriginalLoc()))
+ return true;
+
+ return false;
+}
----------------
Richard Smith wrote:
> 'return Visit(TL.getOriginalLoc());' ?
Done.
================
Comment at: include/clang/AST/ASTContext.h:895-897
@@ +894,5 @@
+
+ /// \brief Returns a DecayedType if T is an array or function. Otherwise
+ /// returns T. Call this instead of getDecayedType() if T's type is unknown.
+ QualType getMaybeDecayedType(QualType T) const;
+
----------------
Richard Smith wrote:
> Please rename to getAdjustedParameterType, and make the existing getAdjustedParameterType local to ASTContext.cpp. I don't think we want to expose a way to perform parameter type decay that doesn't build a DecayedType node.
OK.
================
Comment at: include/clang/AST/RecursiveASTVisitor.h:850-853
@@ -849,1 +849,6 @@
+DEF_TRAVERSE_TYPE(DecayedType, {
+ TRY_TO(TraverseType(T->getDecayedType()));
+ TRY_TO(TraverseType(T->getOriginalType()));
+ })
+
----------------
Richard Smith wrote:
> Seems a bit weird to me to visit both types here. I also worry that this will be exponential-time if we have deeply-nested functions-taking-functions-taking-functions. I suggest you follow our behavior for AttributedType here and visit the original type, not the desugared type.
Sounds good. I wasn't really sure what to do.
http://llvm-reviews.chandlerc.com/D1014
More information about the cfe-commits
mailing list