[CodeGen] Fix assertion on referencing constexpr Obj-C object with ARC.
authorVolodymyr Sapsai <vsapsai@apple.com>
Thu, 1 Nov 2018 22:50:08 +0000 (22:50 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Thu, 1 Nov 2018 22:50:08 +0000 (22:50 +0000)
commit8b286f99d4d39aa7847c85f00c111a577a354fef
tree76495930cb445961344a9239b4b4e709c45cb436
parent5853762e5a6d02ef2e7279c418fbc94a6b1c7a21
[CodeGen] Fix assertion on referencing constexpr Obj-C object with ARC.

Failed assertion is
> Assertion failed: ((ND->isUsed(false) || !isa<VarDecl>(ND) || !E->getLocation().isValid()) && "Should not use decl without marking it used!"), function EmitDeclRefLValue, file llvm-project/clang/lib/CodeGen/CGExpr.cpp, line 2437.

`EmitDeclRefLValue` mentions
> // A DeclRefExpr for a reference initialized by a constant expression can
> // appear without being odr-used. Directly emit the constant initializer.

The fix is to use the similar approach for non-references as for references. It
is achieved by trying to emit a constant before we attempt to load non-odr-used
variable as LValue.

rdar://problem/40650504

Reviewers: ahatanak, rjmccall

Reviewed By: rjmccall

Subscribers: dexonsmith, erik.pilkington, cfe-commits

Differential Revision: https://reviews.llvm.org/D53674

llvm-svn: 345903
clang/lib/CodeGen/CGObjC.cpp
clang/test/CodeGenObjCXX/arc-constexpr.mm