summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2019-07-09 15:02:07 +0000
committerAaron Ballman <aaron@aaronballman.com>2019-07-09 15:02:07 +0000
commitb1e511bf5a4c702ace445848b30070ac2e021241 (patch)
tree22de771c7632577d77a3949f333a3231e4ac193a /clang/lib/Sema/SemaExpr.cpp
parentd95557306585404893d610784edb3e32f1bfce18 (diff)
downloadbcm5719-llvm-b1e511bf5a4c702ace445848b30070ac2e021241.tar.gz
bcm5719-llvm-b1e511bf5a4c702ace445848b30070ac2e021241.zip
Ignore trailing NullStmts in StmtExprs for GCC compatibility.
Ignore trailing NullStmts in compound expressions when determining the result type and value. This is to match the GCC behavior which ignores semicolons at the end of compound expressions. Patch by Dominic Ferreira. llvm-svn: 365498
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 466d9fdb9b9..668abd2bec2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13432,7 +13432,9 @@ Sema::ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
QualType Ty = Context.VoidTy;
bool StmtExprMayBindToTemp = false;
if (!Compound->body_empty()) {
- if (const auto *LastStmt = dyn_cast<ValueStmt>(Compound->body_back())) {
+ // For GCC compatibility we get the last Stmt excluding trailing NullStmts.
+ if (const auto *LastStmt =
+ dyn_cast<ValueStmt>(Compound->getStmtExprResult())) {
if (const Expr *Value = LastStmt->getExprStmt()) {
StmtExprMayBindToTemp = true;
Ty = Value->getType();
OpenPOWER on IntegriCloud