[LLVMbugs] [Bug 22728] New: Many allocations in clang aren't correctly aligned.
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Feb 27 09:57:26 PST 2015
http://llvm.org/bugs/show_bug.cgi?id=22728
Bug ID: 22728
Summary: Many allocations in clang aren't correctly aligned.
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: ahmed.bougacha at gmail.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Consider "DeclRefExpr::Create(.., NameInfo, ..)". It allocates itself
and a few other structs in a single allocation, using the well-known
pattern:
std::size_t Size = sizeof(DeclRefExpr);
if (...)
Size += sizeof(...);
...
void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>());
The alignment should also take into account the trailing classes,
really. In every Allocate call that has a non-trivial size, the
alignment should be correspondingly non-trivial. Some calls just use
ASTContext's default, 8 (enough for most purposes, at least; better
than the explicit alignOf, which might be 4).
[skip forward if you don't care about the investigation]
Currently, I think we get away with this because 1) X86 is lenient, 2)
most people don't self-host on another architecture, and 3) at least
on ARM, alignment checking has to be explicitly enabled, statically or
dynamically.
On ARM, if you try running clang with either:
- SCTRL.A==1 (alignment checking on non-strict-aligned instructions)
(I should say I couldn't get this to work); or
- different LLVM CodeGen picking stricter instructions that actually
enforce alignment (what made me investigate),
it should crash, at some point. On the LIT-tests, the first (of many)
to fail was
test/Analysis/dead-stores.cpp
Indeed, on trunk clang, the "this" pointer in
ASTTemplateArgumentListInfo::initializeFrom(Info, b, b, b)
is sometimes dynamically 4-aligned, whereas it is supposed to be
8-aligned (according to alignof and the IR we generate.)
This pattern is pervasive throughout clang, and even though a few
classes try to get it right (with a trailing AlignedCharArray), most
don't.
UBSan's alignment sanitizer would be *very* useful here. On ARM,
self-hosting clang using clang, with the alignment sanitizer:
-fsanitize=alignment -fsanitize-undefined-trap-on-error
Should exhibit the problems.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150227/aee07ca4/attachment.html>
More information about the llvm-bugs
mailing list