Author: ahatanak Date: Fri Jan 6 11:56:15 2017 New Revision: 291253 URL: http://llvm.org/viewvc/llvm-project?rev=291253&view=rev Log: 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 Modified: cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/test/Sema/warn-cast-align.c Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=291253&r1=291252&r2=291253&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jan 6 11:56:15 2017 @@ -1458,7 +1458,9 @@ CharUnits ASTContext::getDeclAlign(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)) { Modified: cfe/trunk/test/Sema/warn-cast-align.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-cast-align.c?rev=291253&r1=291252&r2=291253&view=diff ============================================================================== --- cfe/trunk/test/Sema/warn-cast-align.c (original) +++ cfe/trunk/test/Sema/warn-cast-align.c Fri Jan 6 11:56:15 2017 @@ -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; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits