@@ -299,6 +299,19 @@ namespace {
299
299
raw_pwrite_stream& nl (raw_pwrite_stream &Out, int delta = 0 );
300
300
301
301
private:
302
+
303
+ // LLVM changed stripPointerCasts to use the "returned" attribute on
304
+ // calls and invokes, i.e., stripping pointer casts of a call to
305
+ // define internal i8* @strupr(i8* returned %str) #2 {
306
+ // will return the pointer, and ignore the call which has side
307
+ // effects. We sometimes do care about the side effects.
308
+ const Value* stripPointerCastsWithoutSideEffects (const Value* V) {
309
+ if (isa<CallInst>(V) || isa<InvokeInst>(V)) {
310
+ return V; // in theory we could check if there actually are side effects
311
+ }
312
+ return V->stripPointerCasts ();
313
+ }
314
+
302
315
void printCommaSeparated (const HeapData v);
303
316
304
317
// parsing of constants has two phases: calculate, and then emit
@@ -1679,7 +1692,7 @@ std::string JSWriter::getConstantVector(const ConstantVectorType *C) {
1679
1692
1680
1693
std::string JSWriter::getValueAsStr (const Value* V, AsmCast sign) {
1681
1694
// Skip past no-op bitcasts and zero-index geps.
1682
- V = V-> stripPointerCasts ( );
1695
+ V = stripPointerCastsWithoutSideEffects (V );
1683
1696
1684
1697
if (const Constant *CV = dyn_cast<Constant>(V)) {
1685
1698
return getConstant (CV, sign);
@@ -1690,7 +1703,7 @@ std::string JSWriter::getValueAsStr(const Value* V, AsmCast sign) {
1690
1703
1691
1704
std::string JSWriter::getValueAsCastStr (const Value* V, AsmCast sign) {
1692
1705
// Skip past no-op bitcasts and zero-index geps.
1693
- V = V-> stripPointerCasts ( );
1706
+ V = stripPointerCastsWithoutSideEffects (V );
1694
1707
1695
1708
if (isa<ConstantInt>(V) || isa<ConstantFP>(V)) {
1696
1709
return getConstant (cast<Constant>(V), sign);
@@ -1701,7 +1714,7 @@ std::string JSWriter::getValueAsCastStr(const Value* V, AsmCast sign) {
1701
1714
1702
1715
std::string JSWriter::getValueAsParenStr (const Value* V) {
1703
1716
// Skip past no-op bitcasts and zero-index geps.
1704
- V = V-> stripPointerCasts ( );
1717
+ V = stripPointerCastsWithoutSideEffects (V );
1705
1718
1706
1719
if (const Constant *CV = dyn_cast<Constant>(V)) {
1707
1720
return getConstant (CV);
@@ -1712,7 +1725,7 @@ std::string JSWriter::getValueAsParenStr(const Value* V) {
1712
1725
1713
1726
std::string JSWriter::getValueAsCastParenStr (const Value* V, AsmCast sign) {
1714
1727
// Skip past no-op bitcasts and zero-index geps.
1715
- V = V-> stripPointerCasts ( );
1728
+ V = stripPointerCastsWithoutSideEffects (V );
1716
1729
1717
1730
if (isa<ConstantInt>(V) || isa<ConstantFP>(V) || isa<UndefValue>(V)) {
1718
1731
return getConstant (cast<Constant>(V), sign);
@@ -2362,7 +2375,7 @@ void JSWriter::generateExpression(const User *I, raw_string_ostream& Code) {
2362
2375
// and all-zero-index geps that LLVM needs to satisfy its type system, we
2363
2376
// call stripPointerCasts() on all values before translating them. This
2364
2377
// includes bitcasts whose only use is lifetime marker intrinsics.
2365
- assert (I == I-> stripPointerCasts ( ));
2378
+ assert (I == stripPointerCastsWithoutSideEffects (I ));
2366
2379
2367
2380
Type *T = I->getType ();
2368
2381
if (T->isIntegerTy () && ((!OnlyWebAssembly && T->getIntegerBitWidth () > 32 ) ||
@@ -2961,7 +2974,7 @@ void JSWriter::addBlock(const BasicBlock *BB, Relooper& R, LLVMToRelooperMap& LL
2961
2974
for (BasicBlock::const_iterator II = BB->begin (), E = BB->end ();
2962
2975
II != E; ++II) {
2963
2976
auto I = &*II;
2964
- if (I-> stripPointerCasts ( ) == I) {
2977
+ if (stripPointerCastsWithoutSideEffects (I ) == I) {
2965
2978
CurrInstruction = I;
2966
2979
generateExpression (I, CodeStream);
2967
2980
}
0 commit comments