[PATCH] D16465: [MS ABI] Prevent some expressions from evaluating to a constant

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 22 10:43:48 PST 2016


rnk added a comment.

Your code won't catch this test case:

  static int x;
  extern inline const bool *f() {
    static const bool p = !&x;
    return &p;
  }

Getting this exactly right is going to be a challenge. =/


================
Comment at: include/clang/Basic/DiagnosticASTKinds.td:151
@@ -150,1 +150,3 @@
   "%plural{1:byte|:bytes}1">;
+def note_constexpr_microsoft_abi_declrefexpr : Note<
+  "the constant expression cannot contain a reference to a variable as a Microsoft "
----------------
We should add this test case and decide what to do with it:
  static int x;
  inline int **f() {
    static constexpr int *p = true ? 0 : &x;
    return &p;
  }
Currently, in your patch, this diagnostic will come out. MSVC compiles this to guarded, dynamic initialization, despite the constexpr. ;_;

David thinks we should just give the user the real deal constexpr behavior, even though it's ABI incompatible.

================
Comment at: include/clang/Basic/DiagnosticASTKinds.td:152-153
@@ -151,1 +151,4 @@
+def note_constexpr_microsoft_abi_declrefexpr : Note<
+  "the constant expression cannot contain a reference to a variable as a Microsoft "
+  "ABI extension">;
 
----------------
This isn't an extension, so we should say something else. Maybe:
  "in the Microsoft ABI static local variables cannot contain references to variables"

================
Comment at: lib/AST/ExprConstant.cpp:9008
@@ -8917,1 +9007,3 @@
 
+  if (Ctx.getTargetInfo().getCXXABI().isMicrosoft())
+    InitInfo.useMicrosoftABI();
----------------
This should be limited in scope to only apply to static locals. We should be able to statically initialize globals.


http://reviews.llvm.org/D16465





More information about the cfe-commits mailing list