]> granicus.if.org Git - clang/commitdiff
Add a bit to ParmVarDecl indicating whether the parameter undergoes
authorJohn McCall <rjmccall@apple.com>
Wed, 9 Mar 2011 04:22:44 +0000 (04:22 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 9 Mar 2011 04:22:44 +0000 (04:22 +0000)
K&R-style default argument promotion.

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

include/clang/AST/Decl.h
lib/Sema/SemaType.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp

index 24ad92141e30c39a41915644ed7978c9cfad1b29..016e2b338c4696657eab3613d43095d8707fa2ea 100644 (file)
@@ -1099,7 +1099,13 @@ class ParmVarDecl : public VarDecl {
   /// FIXME: Also can be paced into the bitfields in Decl.
   /// in, inout, etc.
   unsigned objcDeclQualifier : 6;
-  bool HasInheritedDefaultArg : 1;
+
+  /// Whether this parameter inherits a default argument from a prior
+  /// declaration.
+  unsigned HasInheritedDefaultArg : 1;
+
+  /// Whether this parameter undergoes K&R argument promotion.
+  unsigned IsKNRPromoted : 1;
 
 protected:
   ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
@@ -1107,7 +1113,8 @@ protected:
               QualType T, TypeSourceInfo *TInfo,
               StorageClass S, StorageClass SCAsWritten, Expr *DefArg)
     : VarDecl(DK, DC, StartLoc, IdLoc, Id, T, TInfo, S, SCAsWritten),
-      objcDeclQualifier(OBJC_TQ_None), HasInheritedDefaultArg(false) {
+      objcDeclQualifier(OBJC_TQ_None), HasInheritedDefaultArg(false),
+      IsKNRPromoted(false) {
     setDefaultArg(DefArg);
   }
 
@@ -1126,6 +1133,17 @@ public:
     objcDeclQualifier = QTVal;
   }
 
+  /// True if the value passed to this parameter must undergo
+  /// K&R-style default argument promotion:
+  ///
+  /// C99 6.5.2.2.
+  ///   If the expression that denotes the called function has a type
+  ///   that does not include a prototype, the integer promotions are
+  ///   performed on each argument, and arguments that have type float
+  ///   are promoted to double.
+  bool isKNRPromoted() const { return IsKNRPromoted; }
+  void setKNRPromoted(bool promoted) { IsKNRPromoted = promoted; }
+
   Expr *getDefaultArg();
   const Expr *getDefaultArg() const {
     return const_cast<ParmVarDecl *>(this)->getDefaultArg();
index 20a85225a468733df4b474ee5b59ad0d02f69a6c..8e857f1a6786fd8f5754fb31f9fd8eb86a6b68fc 100644 (file)
@@ -1873,9 +1873,12 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
           } else if (!FTI.hasPrototype) {
             if (ArgTy->isPromotableIntegerType()) {
               ArgTy = Context.getPromotedIntegerType(ArgTy);
+              Param->setKNRPromoted(true);
             } else if (const BuiltinType* BTy = ArgTy->getAs<BuiltinType>()) {
-              if (BTy->getKind() == BuiltinType::Float)
+              if (BTy->getKind() == BuiltinType::Float) {
                 ArgTy = Context.DoubleTy;
+                Param->setKNRPromoted(true);
+              }
             }
           }
 
index 81aad61698bd831b18cac7dd0b9ac319bfcc32d8..60fcc14d611f7293234d8fcd64516182a7aced7b 100644 (file)
@@ -702,6 +702,7 @@ void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
 void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
   VisitVarDecl(PD);
   PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
+  PD->setKNRPromoted(Record[Idx++]);
   PD->setHasInheritedDefaultArg(Record[Idx++]);
   if (Record[Idx++]) // hasUninstantiatedDefaultArg.
     PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
index a5c439804209cb3dd9610f771a7ccc1adc1b3d73..95b0c3c4dbf3181e8d3a568c811496870a018cf7 100644 (file)
@@ -577,6 +577,7 @@ void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
 void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
   VisitVarDecl(D);
   Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
+  Record.push_back(D->isKNRPromoted());
   Record.push_back(D->hasInheritedDefaultArg());
   Record.push_back(D->hasUninstantiatedDefaultArg());
   if (D->hasUninstantiatedDefaultArg())
@@ -595,6 +596,7 @@ void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
       D->getStorageClass() == 0 &&
       !D->hasCXXDirectInitializer() && // Can params have this ever?
       D->getObjCDeclQualifier() == 0 &&
+      !D->isKNRPromoted() &&
       !D->hasInheritedDefaultArg() &&
       D->getInit() == 0 &&
       !D->hasUninstantiatedDefaultArg())  // No default expr.
@@ -1147,6 +1149,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
   Abv->Add(BitCodeAbbrevOp(0));                   // HasMemberSpecializationInfo
   // ParmVarDecl
   Abv->Add(BitCodeAbbrevOp(0));                       // ObjCDeclQualifier
+  Abv->Add(BitCodeAbbrevOp(0));                       // KNRPromoted
   Abv->Add(BitCodeAbbrevOp(0));                       // HasInheritedDefaultArg
   Abv->Add(BitCodeAbbrevOp(0));                   // HasUninstantiatedDefaultArg