[PATCH] D57086: Ignore trailing NullStmts in StmtExprs for GCC compatibility

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 23 06:17:32 PST 2019


aaron.ballman edited reviewers, added: aaron.ballman; removed: lattner.
aaron.ballman added a comment.

Can you also add a test case to `TestMiscStmts()` in clang\test\AST\ast-dump-stmt.c that demonstrates we calculate the correct resulting type and don't lose the extra null statements from the AST?



================
Comment at: clang/lib/Parse/ParseStmt.cpp:962
   if (Actions.isCurCompoundStmtAStmtExpr()) {
-    // Look to see if the next two tokens close the statement expression;
-    // if so, this expression statement is the last statement in a
-    // statment expression.
-    return Tok.isNot(tok::r_brace) || NextToken().isNot(tok::r_paren);
+    // For gcc compatibility we skip past NullStmts
+    int LookAhead = 0;
----------------
gcc -> GCC

Also, add a full stop to the end of the comment.


================
Comment at: clang/lib/Parse/ParseStmt.cpp:963
+    // For gcc compatibility we skip past NullStmts
+    int LookAhead = 0;
+    while (GetLookAheadToken(LookAhead).is(tok::semi)) {
----------------
This should be `unsigned` rather than `int`.


================
Comment at: clang/lib/Parse/ParseStmt.cpp:965
+    while (GetLookAheadToken(LookAhead).is(tok::semi)) {
+      LookAhead++;
+    }
----------------
Prefer `++LookHead;` since the result isn't needed.


================
Comment at: clang/lib/Parse/ParseStmt.cpp:971
+    // expression.
+
+    return GetLookAheadToken(LookAhead).isNot(tok::r_brace) ||
----------------
Remove spurious newline.


================
Comment at: clang/lib/Sema/SemaExpr.cpp:13324
+  // as the type of the stmtexpr. For GCC compatibility this excludes trailing
+  // NullStmts
   QualType Ty = Context.VoidTy;
----------------
Add full stop to the end of the sentence.


================
Comment at: clang/lib/Sema/SemaExpr.cpp:13328
   if (!Compound->body_empty()) {
-    Stmt *LastStmt = Compound->body_back();
+    // GCC ignores empty statements at the end of compound expressions
+    // i.e. ({ 5;;; })
----------------
Add full stop to the end of the sentence.


================
Comment at: clang/lib/Sema/SemaExpr.cpp:13331
+    //           ^^ ignored
+    // This code skips past these NullStmts
+    Stmt *LastStmt = nullptr;
----------------
Add full stop to the end of the sentence.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57086/new/

https://reviews.llvm.org/D57086





More information about the cfe-commits mailing list