aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-03-08 21:02:16 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-03-08 21:02:16 -0800
commit60283d939f64ea8825a8c6a2b7de2a7cdefd4f39 (patch)
treeb9ffafd4a100be9aa8ca1c2b955aedc5704e8eb6 /lib
parent3b5ab8f9039635fda547290fda398c1cd350423a (diff)
resolve constants fully, through both multiple aliases and bitcasts
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/JSBackend/JSBackend.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp
index ec33d4cd83..d4fbdad1ee 100644
--- a/lib/Target/JSBackend/JSBackend.cpp
+++ b/lib/Target/JSBackend/JSBackend.cpp
@@ -310,12 +310,26 @@ namespace {
return getBlockAddress(BA->getFunction(), BA->getBasicBlock());
}
+ const Value *resolveFully(const Value *V) {
+ bool More = true;
+ while (More) {
+ More = false;
+ if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
+ V = GA->getAliasee();
+ More = true;
+ }
+ if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
+ V = CE->getOperand(0); // ignore bitcasts
+ More = true;
+ }
+ }
+ return V;
+ }
+
// Return a constant we are about to write into a global as a numeric offset. If the
// value is not known at compile time, emit a postSet to that location.
unsigned getConstAsOffset(const Value *V, unsigned AbsoluteTarget) {
- if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
- V = GA->getAliasee();
- }
+ V = resolveFully(V);
if (const Function *F = dyn_cast<const Function>(V)) {
return getFunctionIndex(F);
} else if (const BlockAddress *BA = dyn_cast<const BlockAddress>(V)) {