[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls
This revision was automatically updated to reflect the committed changes. Closed by commit rL291253: Make ASTContext::getDeclAlign return the correct alignment for (authored by ahatanak). Changed prior to commit: https://reviews.llvm.org/D27478?vs=80464=83378#toc Repository: rL LLVM https://reviews.llvm.org/D27478 Files: cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/test/Sema/warn-cast-align.c Index: cfe/trunk/test/Sema/warn-cast-align.c === --- cfe/trunk/test/Sema/warn-cast-align.c +++ cfe/trunk/test/Sema/warn-cast-align.c @@ -59,3 +59,11 @@ i = (int *) i = (int *)a; } + +// No warnings. +typedef int (*FnTy)(void); +unsigned int func5(void); + +FnTy test5(void) { + return (FnTy) +} Index: cfe/trunk/lib/AST/ASTContext.cpp === --- cfe/trunk/lib/AST/ASTContext.cpp +++ cfe/trunk/lib/AST/ASTContext.cpp @@ -1458,7 +1458,9 @@ 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)) { Index: cfe/trunk/test/Sema/warn-cast-align.c === --- cfe/trunk/test/Sema/warn-cast-align.c +++ cfe/trunk/test/Sema/warn-cast-align.c @@ -59,3 +59,11 @@ i = (int *) i = (int *)a; } + +// No warnings. +typedef int (*FnTy)(void); +unsigned int func5(void); + +FnTy test5(void) { + return (FnTy) +} Index: cfe/trunk/lib/AST/ASTContext.cpp === --- cfe/trunk/lib/AST/ASTContext.cpp +++ cfe/trunk/lib/AST/ASTContext.cpp @@ -1458,7 +1458,9 @@ 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)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls
arphaman accepted this revision. arphaman added a reviewer: arphaman. arphaman added a comment. This revision is now accepted and ready to land. Thanks. LGTM, I think the patch makes sense. https://reviews.llvm.org/D27478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls
ahatanak added a comment. ping https://reviews.llvm.org/D27478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls
ahatanak added a comment. This doesn't happen for objective-c block pointers. Sema::CheckCastAlign returns early when the type isn't a PointerType (BlockPointerType isn't a subclass of PointerType). https://reviews.llvm.org/D27478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls
arphaman added a comment. Does this happen with blocks as well? https://reviews.llvm.org/D27478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls
ahatanak updated this revision to Diff 80464. ahatanak added a comment. Call getTypeInfoImpl from getDeclAlign to get the alignment of functions. https://reviews.llvm.org/D27478 Files: lib/AST/ASTContext.cpp test/Sema/warn-cast-align.c Index: test/Sema/warn-cast-align.c === --- test/Sema/warn-cast-align.c +++ test/Sema/warn-cast-align.c @@ -59,3 +59,11 @@ i = (int *) i = (int *)a; } + +// No warnings. +typedef int (*FnTy)(void); +unsigned int func5(void); + +FnTy test5(void) { + return (FnTy) +} Index: lib/AST/ASTContext.cpp === --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -1455,7 +1455,9 @@ 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)) { Index: test/Sema/warn-cast-align.c === --- test/Sema/warn-cast-align.c +++ test/Sema/warn-cast-align.c @@ -59,3 +59,11 @@ i = (int *) i = (int *)a; } + +// No warnings. +typedef int (*FnTy)(void); +unsigned int func5(void); + +FnTy test5(void) { + return (FnTy) +} Index: lib/AST/ASTContext.cpp === --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -1455,7 +1455,9 @@ 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)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls
ahatanak created this revision. ahatanak added reviewers: rsmith, doug.gregor. ahatanak added a subscriber: cfe-commits. This patch 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). https://reviews.llvm.org/D27478 Files: lib/AST/ASTContext.cpp test/Sema/warn-cast-align.c Index: test/Sema/warn-cast-align.c === --- test/Sema/warn-cast-align.c +++ test/Sema/warn-cast-align.c @@ -59,3 +59,11 @@ i = (int *) i = (int *)a; } + +// No warnings. +typedef int (*FnTy)(void); +unsigned int func5(void); + +FnTy test5(void) { + return (FnTy) +} Index: lib/AST/ASTContext.cpp === --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -1501,7 +1501,9 @@ Align = std::min(Align, FieldAlign); } -} +} else if (isa(VD)) + // GCC extension: alignment of functions is 32 bits + Align = 32; } return toCharUnitsFromBits(Align); Index: test/Sema/warn-cast-align.c === --- test/Sema/warn-cast-align.c +++ test/Sema/warn-cast-align.c @@ -59,3 +59,11 @@ i = (int *) i = (int *)a; } + +// No warnings. +typedef int (*FnTy)(void); +unsigned int func5(void); + +FnTy test5(void) { + return (FnTy) +} Index: lib/AST/ASTContext.cpp === --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -1501,7 +1501,9 @@ Align = std::min(Align, FieldAlign); } -} +} else if (isa(VD)) + // GCC extension: alignment of functions is 32 bits + Align = 32; } return toCharUnitsFromBits(Align); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits