[PATCH] D46234: Mark if a null statement is the result of constexpr folding

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 29 05:01:39 PDT 2018


xazax.hun created this revision.
xazax.hun added a reviewer: aaron.ballman.
Herald added subscribers: dkrupp, rnkovacs.

I did not add tests yet because first I wanted to be sure whether this approach is OK.


Repository:
  rC Clang

https://reviews.llvm.org/D46234

Files:
  include/clang/AST/Stmt.h
  lib/Sema/TreeTransform.h


Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -6605,7 +6605,9 @@
     if (Then.isInvalid())
       return StmtError();
   } else {
-    Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
+    Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart(),
+                                            /*hasLeadingEmptyMacro=*/false,
+                                            /*resultOfConstexprFolding=*/true);
   }
 
   // Transform the "else" branch.
Index: include/clang/AST/Stmt.h
===================================================================
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -577,21 +577,33 @@
   /// @endcode
   bool HasLeadingEmptyMacro = false;
 
+  /// \brief True if the null statement was produced by folding a part of the
+  ///        code away, e.g:
+  /// @code
+  ///   if constexpr(0 > 1) { willBeFoldedAway(); }
+  ///   // After constexpr evaluation:
+  ///   if constexpr(0 > 1) ;
+  /// @endcode
+  bool ResultOfConstexprFolding = false;
+
 public:
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
 
-  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
+  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false,
+           bool resultOfConstexprFolding = false)
       : Stmt(NullStmtClass), SemiLoc(L),
-        HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
+        HasLeadingEmptyMacro(hasLeadingEmptyMacro),
+        ResultOfConstexprFolding(resultOfConstexprFolding) {}
 
   /// \brief Build an empty null statement.
   explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {}
 
   SourceLocation getSemiLoc() const { return SemiLoc; }
   void setSemiLoc(SourceLocation L) { SemiLoc = L; }
 
   bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
+  bool resultOfConstexprFolding() const { return ResultOfConstexprFolding; }
 
   SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
   SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46234.144477.patch
Type: text/x-patch
Size: 2129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180429/701f685e/attachment.bin>


More information about the cfe-commits mailing list