Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Commit 349752c

Browse files
lateralusXluhenry
authored andcommitted
Workaround for mingw i686 compiler optimization bug. (#19)
32-bit llc.exe build using i686-w64-mingw32-gcc/i686-w64-mingw32-g++ at least on version 5.3.1 and 5.4.0 triggers an optimization bug crashing the process. This was observed by Android team when running cross compiler targeting armv7-linux-gnueabi using LLVM 6.0. The MatchPhiSet call from findCommon triggered an optimization resulting in incorrect stack pointer adjustment on return. That in turn caused an AV when reading the incorrect pointer from stack representing NewPhiNodes stack variable. The fix will reduce optimization around this function not triggering the optimization rules hitting the bug.
1 parent 76f65d6 commit 349752c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,17 @@ class AddressingModeCombiner {
28082808
// Request is
28092809
// <p, BB3> -> ?
28102810
// The function tries to find or build phi [b1, BB1], [b2, BB2] in BB3
2811+
#if defined(__MINGW32__)
2812+
// This function triggers an optimization error in i686-w64-mingw32-gcc/i686-w64-mingw32-g++
2813+
// at least observed in 5.3.1 and 5.4.0. Since these mingw releases are the ones currently
2814+
// fetched by package managers building LLVM cross compilers targeting Windows, this make sure
2815+
// this method only gets compiled with an optimization level not triggering this bug. When the
2816+
// optimization error occurs it results in an incorrect stack pointer restore after the call to
2817+
// MatchPhiSet and since this method uses FPO next instruction loading NewPhiNodes relative stack pointer
2818+
// will get incorrect value triggering an access violation.
2819+
#pragma GCC push_options
2820+
#pragma GCC optimize ("O1")
2821+
#endif
28112822
Value *findCommon(FoldAddrToValueMapping &Map) {
28122823
// Tracks of new created Phi nodes.
28132824
SmallPtrSet<PHINode *, 32> NewPhiNodes;
@@ -2849,6 +2860,9 @@ class AddressingModeCombiner {
28492860
}
28502861
return Result;
28512862
}
2863+
#if defined(__MINGW32__)
2864+
#pragma GCC pop_options
2865+
#endif
28522866

28532867
/// \brief Destroy nodes from a set.
28542868
template <typename T> void DestroyNodes(SmallPtrSetImpl<T *> &Instructions) {

0 commit comments

Comments
 (0)