This is an archive of the discontinued LLVM Phabricator instance.

CodeGen: Make constant emission of arrays and structs more aggressive.
Needs ReviewPublic

Authored by bkramer on Mar 7 2015, 9:54 AM.

Details

Reviewers
rsmith
Summary

The limitation to POD types stems from the times when our constant emission
logic was way less sophisticated and much more buggy. Emit all constant
initializers as LLVM constants.

This reuses the logic for static vars, so assert that we don't accidentally
introduce a static initializer. I tried to cover the issues mentioned in the
commit with additional test cases.

Diff Detail

Event Timeline

bkramer updated this revision to Diff 21423.Mar 7 2015, 9:54 AM
bkramer retitled this revision from to CodeGen: Make constant emission of arrays and structs more aggressive..
bkramer updated this object.
bkramer added a reviewer: rsmith.
bkramer added a subscriber: Unknown Object (MLST).
rsmith added inline comments.Mar 9 2015, 5:47 PM
lib/CodeGen/CGDecl.cpp
890–894

There are still cases that isConstantInitializer gets wrong. For instance, we don't check that the array filler is a constant for an array InitListExpr:

struct X { X(); constexpr X(int) {} }; X x[3] = { 3 };

(You can see that there's a problem here because we emit dynamic initialization code but no -Wglobal-constructors warning.)

(Unrelated to your change) The bitfield case is still broken; this asserts:

struct X { long n : 3; }; int k; X x = { (long)&k };