summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/APValue.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2019-03-06 10:26:19 +0000
committerHans Wennborg <hans@hanshq.net>2019-03-06 10:26:19 +0000
commitdd1ea8abb791d274ae574a478937aa0e77cc405f (patch)
treeb1245fa18b95148a743b90909794e1b763b8c701 /clang/lib/AST/APValue.cpp
parent2a0f2c5ef3330846149598220467d9f3c6e8b99c (diff)
downloadbcm5719-llvm-dd1ea8abb791d274ae574a478937aa0e77cc405f.tar.gz
bcm5719-llvm-dd1ea8abb791d274ae574a478937aa0e77cc405f.zip
Inline asm constraints: allow ICE-like pointers for the "n" constraint (PR40890)
Apparently GCC allows this, and there's code relying on it (see bug). The idea is to allow expression that would have been allowed if they were cast to int. So I based the code on how such a cast would be done (the CK_PointerToIntegral case in IntExprEvaluator::VisitCastExpr()). Differential Revision: https://reviews.llvm.org/D58821 llvm-svn: 355491
Diffstat (limited to 'clang/lib/AST/APValue.cpp')
-rw-r--r--clang/lib/AST/APValue.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index e1876a933dc..f9cbf331b28 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -614,6 +614,26 @@ std::string APValue::getAsString(ASTContext &Ctx, QualType Ty) const {
return Result;
}
+bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
+ const ASTContext &Ctx) const {
+ if (isInt()) {
+ Result = getInt();
+ return true;
+ }
+
+ if (isLValue() && isNullPointer()) {
+ Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
+ return true;
+ }
+
+ if (isLValue() && !getLValueBase()) {
+ Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
+ return true;
+ }
+
+ return false;
+}
+
const APValue::LValueBase APValue::getLValueBase() const {
assert(isLValue() && "Invalid accessor");
return ((const LV*)(const void*)Data.buffer)->Base;
OpenPOWER on IntegriCloud