[PATCH] CodeGen: Make constant emission of arrays and structs more aggressive.

Richard Smith richard at metafoo.co.uk
Mon Mar 9 17:47:57 PDT 2015


================
Comment at: lib/CodeGen/CGDecl.cpp:890-894
@@ -889,7 +889,1 @@
-    //
-    // TODO: We should constant-evaluate the initializer of any variable,
-    // as long as it is initialized by a constant expression. Currently,
-    // isConstantInitializer produces wrong answers for structs with
-    // reference or bitfield members, and a few other cases, and checking
-    // for POD-ness protects us from some of these.
     if (D.getInit() && (Ty->isArrayType() || Ty->isRecordType()) &&
----------------
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 };

http://reviews.llvm.org/D8137

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list