From f1649bd7082675672974be0c60080aa34b1e350a Mon Sep 17 00:00:00 2001 From: David Tarditi Date: Tue, 10 Sep 2019 16:25:18 -0700 Subject: [PATCH] Fix compiler assertion when subscripting a call expression. (#605) Cherry-picked from commit a35072baee9fcb267e0e2dc2842fa55a600eca0f We introduce temporary variables to hold the results of calls to functions that return pointers with bounds. This lets us express the bounds of the result of the call in the IR, so that we can generate a bounds check. There is an assertion failure during code generation. The wrong map is being used to look up the LLVM value for the temporary variable for an rvalue. Use the right map. Testing: - Passes tests of subscripting call expressions. --- clang/lib/CodeGen/CGExprScalar.cpp | 2 +- clang/lib/CodeGen/CodeGenFunction.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index e09793b7bf72..2fe946c82624 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -807,7 +807,7 @@ class ScalarExprEmitter if (E->getKind() == BoundsValueExpr::Kind::Temporary) { CHKCBindTemporaryExpr *Temp = E->getTemporaryBinding(); assert(!Temp->getSubExpr()->isLValue()); - Result = CGF.getBoundsTemporaryLValueMapping(Temp).getPointer(); + Result = CGF.getBoundsTemporaryRValueMapping(Temp).getScalarVal(); } else llvm_unreachable("unexpected bounds value expr"); assert(Result); diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 2f24e6225975..49c1390954c4 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2113,9 +2113,9 @@ class CodeGenFunction : public CodeGenTypeCache { return it->second; } - /// getBoundsTemporaryLValueMapping - Given a bounds temporary (which + /// getBoundsTemporaryRValueMapping - Given a bounds temporary (which /// must be mapped to an l-value), return its mapping. - const RValue &getBoundsTemporaryRValueMapping(const CHKCBindTemporaryExpr *e) { + RValue getBoundsTemporaryRValueMapping(const CHKCBindTemporaryExpr *e) { assert (!e->getSubExpr()->isLValue()); llvm::DenseMap::iterator