[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 6 12:47:06 PST 2016


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 *)&s.s0;
   i = (int *)a;
 }
+
+// No warnings.
+typedef int (*FnTy)(void);
+unsigned int func5(void);
+
+FnTy test5(void) {
+  return (FnTy)&func5;
+}
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)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27478.80464.patch
Type: text/x-patch
Size: 993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161206/1750e699/attachment.bin>


More information about the cfe-commits mailing list