diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2017-01-06 17:56:15 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2017-01-06 17:56:15 +0000 |
commit | d62f2c8c0a9d21087223b31e28d5d62b60f708eb (patch) | |
tree | 05521df732a31d2614b633c36cdfa0ed04326aea | |
parent | 98f0af4b3e22092cf1770a72a81cbd0f88017f22 (diff) | |
download | bcm5719-llvm-d62f2c8c0a9d21087223b31e28d5d62b60f708eb.tar.gz bcm5719-llvm-d62f2c8c0a9d21087223b31e28d5d62b60f708eb.zip |
Make ASTContext::getDeclAlign return the correct alignment for
FunctionDecls.
This commit silences an incorrect warning that is issued when a function
pointer is cast to another function pointer type. The warning gets
issued because alignments of the source and destination do not match in
Sema::CheckCastAlign, which happens because ASTContext::getTypeInfoImpl
and ASTContext::getDeclAlign return different values for functions (the
former returns 4 while the latter returns 1).
This should fix PR31558.
rdar://problem/29533528
Differential Revision: https://reviews.llvm.org/D27478
llvm-svn: 291253
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 4 | ||||
-rw-r--r-- | clang/test/Sema/warn-cast-align.c | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 1b5988d0198..d03c22af5b2 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1458,7 +1458,9 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const { T = getPointerType(RT->getPointeeType()); } QualType BaseT = getBaseElementType(T); - if (!BaseT->isIncompleteType() && !T->isFunctionType()) { + if (T->isFunctionType()) + Align = getTypeInfoImpl(T.getTypePtr()).Align; + else if (!BaseT->isIncompleteType()) { // Adjust alignments of declarations with array type by the // large-array alignment on the target. if (const ArrayType *arrayType = getAsArrayType(T)) { diff --git a/clang/test/Sema/warn-cast-align.c b/clang/test/Sema/warn-cast-align.c index e8f85bc14d8..389c0c17d2f 100644 --- a/clang/test/Sema/warn-cast-align.c +++ b/clang/test/Sema/warn-cast-align.c @@ -59,3 +59,11 @@ void test4() { i = (int *)&s.s0; i = (int *)a; } + +// No warnings. +typedef int (*FnTy)(void); +unsigned int func5(void); + +FnTy test5(void) { + return (FnTy)&func5; +} |