aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/JSBackend/JSBackend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Target/JSBackend/JSBackend.cpp')
-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)) {