This is an archive of the discontinued LLVM Phabricator instance.

Implement __builtin_alloca_with_align for GCC compatibility
AbandonedPublic

Authored by rnk on Oct 13 2016, 3:46 PM.

Details

Reviewers
rsmith
Summary

GCC documents that the alignment parameter is in bits and it must be:

  • an integer constant
  • a power of two
  • a multiple of CHAR_BITS
  • below an unspecified limit

This lines up directly with the requirements for LLVM's alloca
instruction, so I went ahead and wired it up. We limit the alignment to
1<<29, which is the maximum alignment supported by LLVM's alloca.

Implements feature request in PR30658

Event Timeline

rnk updated this revision to Diff 74592.Oct 13 2016, 3:46 PM
rnk retitled this revision from to Implement __builtin_alloca_with_align for GCC compatibility.
rnk updated this object.
rnk added a reviewer: rsmith.
rnk added a subscriber: cfe-commits.
rsmith added inline comments.Oct 13 2016, 5:48 PM
lib/CodeGen/CGBuiltin.cpp
1037–1039

This takes the alignment in bits? That's so ridiculously dumb that I would feel bad about accepting this patch unless it comes with a warning for people writing the obvious-but-wrong __builtin_alloca_with_align(sizeof(T), alignof(T)).

1038–1039

EvaluateKnownConstInt, perhaps?

1040–1041

CGM.getContext().toCharUnitsFromBits maybe?

lib/Sema/SemaChecking.cpp
971–972

EvaluateKnownConstInt, perhaps?

973

Well, this comment won't cause that to happen. Do you anticipate that value changing?

test/Sema/builtin-alloca.c
7

Can you also add tests for -1 and (__int128)1 << 100? (They should both pass, already, but seem like interesting corner cases regardless.)

rnk abandoned this revision.Nov 30 2016, 1:35 PM
rnk added a subscriber: majnemer.

@majnemer did this in rL285544