diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-06-01 09:24:59 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-06-01 09:24:59 +0000 |
commit | fcbf7d2baffc5e8ced54a918af0c187794443517 (patch) | |
tree | e6cfa62e55ca9fcdbebaed89a20b7b93a33288f4 /clang/lib/Sema/SemaDecl.cpp | |
parent | ee94e3cc9e8188c940246e5bec02a64d5df8f6ac (diff) | |
download | bcm5719-llvm-fcbf7d2baffc5e8ced54a918af0c187794443517.tar.gz bcm5719-llvm-fcbf7d2baffc5e8ced54a918af0c187794443517.zip |
PR4287: allow a variadic prototype to make a subsequent K&R style
definition variadic. I'm not completely sure it's legal, but the
standard can be interpreted as making it legal, and gcc seems to think
it's legal, so I didn't add an extension warning.
llvm-svn: 72689
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9c650e61e7c..959154c4ec1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -765,6 +765,11 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { // promoted types of the parameters from the K&R definition differ // from the types in the prototype. GCC then keeps the types from // the prototype. + // + // If a variadic prototype is followed by a non-variadic K&R definition, + // the K&R definition becomes variadic. This is sort of an edge case, but + // it's legal per the standard depending on how you read C99 6.7.5.3p15 and + // C99 6.9.1p8. if (!getLangOptions().CPlusPlus && Old->hasPrototype() && !New->hasPrototype() && New->getType()->getAsFunctionProtoType() && @@ -777,12 +782,11 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { = New->getType()->getAsFunctionProtoType(); // Determine whether this is the GNU C extension. - bool GNUCompatible = - Context.typesAreCompatible(OldProto->getResultType(), - NewProto->getResultType()) && - (OldProto->isVariadic() == NewProto->isVariadic()); + QualType MergedReturn = Context.mergeTypes(OldProto->getResultType(), + NewProto->getResultType()); + bool LooseCompatible = !MergedReturn.isNull(); for (unsigned Idx = 0, End = Old->getNumParams(); - GNUCompatible && Idx != End; ++Idx) { + LooseCompatible && Idx != End; ++Idx) { ParmVarDecl *OldParm = Old->getParamDecl(Idx); ParmVarDecl *NewParm = New->getParamDecl(Idx); if (Context.typesAreCompatible(OldParm->getType(), @@ -795,10 +799,10 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { Warnings.push_back(Warn); ArgTypes.push_back(NewParm->getType()); } else - GNUCompatible = false; + LooseCompatible = false; } - if (GNUCompatible) { + if (LooseCompatible) { for (unsigned Warn = 0; Warn < Warnings.size(); ++Warn) { Diag(Warnings[Warn].NewParm->getLocation(), diag::ext_param_promoted_not_compatible_with_prototype) @@ -808,10 +812,9 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { diag::note_previous_declaration); } - New->setType(Context.getFunctionType(NewProto->getResultType(), - &ArgTypes[0], ArgTypes.size(), - NewProto->isVariadic(), - NewProto->getTypeQuals())); + New->setType(Context.getFunctionType(MergedReturn, &ArgTypes[0], + ArgTypes.size(), + OldProto->isVariadic(), 0)); return MergeCompatibleFunctionDecls(New, Old); } |