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 in using the similar approach for non-references of
non-odr-used variables. EmitScalarExpr will try to emit constant if
possible and we can use resulting llvm::Value * without performing
EmitLValue.
rdar://problem/40650504
This switch is just checking what you already computed as SuppressResultRetain. Please just assert in the second case that the qualifier is OCL_Weak.
Also, please stay consistent with the surrounding capitalization of local variables.