diff options
author | Reid Kleckner <rnk@google.com> | 2017-01-31 19:37:45 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2017-01-31 19:37:45 +0000 |
commit | 0b009e8269163d8005914b49ae5b921586fbf38c (patch) | |
tree | 49edf85d5baef7925b200507b321121a5905eced /clang/lib/Sema/SemaCast.cpp | |
parent | bd99882cf2c670bdba0837a82b3a5ad634cf52e4 (diff) | |
download | bcm5719-llvm-0b009e8269163d8005914b49ae5b921586fbf38c.tar.gz bcm5719-llvm-0b009e8269163d8005914b49ae5b921586fbf38c.zip |
Extend -Wcast-calling-convention to warn on declarations as well as definitions
My original warning was very conservative and I never revisited the
heuristics that were used.
This would have caught http://crbug.com/687251 at compile time.
llvm-svn: 293677
Diffstat (limited to 'clang/lib/Sema/SemaCast.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCast.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 6222e4cec47..6f9852aaf53 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -1763,13 +1763,12 @@ static void DiagnoseCallingConvCast(Sema &Self, const ExprResult &SrcExpr, if (!DRE) return; auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()); - const FunctionDecl *Definition; - if (!FD || !FD->hasBody(Definition)) + if (!FD) return; // Only warn if we are casting from the default convention to a non-default // convention. This can happen when the programmer forgot to apply the calling - // convention to the function definition and then inserted this cast to + // convention to the function declaration and then inserted this cast to // satisfy the type system. CallingConv DefaultCC = Self.getASTContext().getDefaultCallingConvention( FD->isVariadic(), FD->isCXXInstanceMember()); @@ -1792,7 +1791,7 @@ static void DiagnoseCallingConvCast(Sema &Self, const ExprResult &SrcExpr, // whose address was taken. Try to use the latest macro for the convention. // For example, users probably want to write "WINAPI" instead of "__stdcall" // to match the Windows header declarations. - SourceLocation NameLoc = Definition->getNameInfo().getLoc(); + SourceLocation NameLoc = FD->getFirstDecl()->getNameInfo().getLoc(); Preprocessor &PP = Self.getPreprocessor(); SmallVector<TokenValue, 6> AttrTokens; SmallString<64> CCAttrText; |