[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:26:08 PST 2016
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 *)&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
@@ -1501,7 +1501,9 @@
Align = std::min(Align, FieldAlign);
}
- }
+ } else if (isa<FunctionDecl>(VD))
+ // GCC extension: alignment of functions is 32 bits
+ Align = 32;
}
return toCharUnitsFromBits(Align);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27478.80463.patch
Type: text/x-patch
Size: 750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161206/d8f0f2b2/attachment.bin>
More information about the cfe-commits
mailing list