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

Dominic Ferreira via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 30 17:07:11 PST 2019


domdom marked an inline comment as not done.
domdom added inline comments.


================
Comment at: clang/include/clang/AST/Stmt.h:1259
+  // the index of the last one.
+  unsigned getLastNonNullStmt() const {
+    assert(!body_empty() && "getLastNonNullStmt");
----------------
aaron.ballman wrote:
> How about `getIndexOfLastNonNullStmt()` since it doesn't return the `Stmt*` itself?
Agreed.


================
Comment at: clang/include/clang/AST/Stmt.h:1300
+  void setStmtExpr(Stmt *S) {
+    assert(!body_empty() && "setStmtExpr");
+    unsigned ExprResult = getLastNonNullStmt();
----------------
getLastNonNullStmt asserts anyway, should I remove this?


================
Comment at: clang/lib/CodeGen/CGStmt.cpp:390
+      E = S.body_end(); I != E; ++I) {
+    if (GetLast && ExprResult == *I) {
+      // We have to special case labels here.  They are statements, but when put
----------------
aaron.ballman wrote:
> What happens if `ExprResult` is `nullptr`?
Then ExprResult == *I should not be evaluated. (Since GetLast would be false)


================
Comment at: clang/test/CodeGen/exprs.c:202
+int f19() {
+  return ({ 3;;4;; });
+}
----------------
aaron.ballman wrote:
> Does this test need the extra null statement between the `3;` and `4;`?
Not strictly speaking, no. Just added it to ensure it has no effect.


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

https://reviews.llvm.org/D57086





More information about the cfe-commits mailing list