Issue |
81013
|
Summary |
Unable to compile LLVM with GCC 8.1
|
Labels |
new issue
|
Assignees |
|
Reporter |
jabraham17
|
I am currently unable to compile LLVM using GCC 8.1.0. The failure comes from `llvm/lib/Support/APFloat.cpp`, where some versions of GCC do not consider an enum a valid constant _expression_. This only seems to be a problem with GCC 8.1 and 8.2, but these are both supported compilers according to <https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library>.
Below is the build failure with LLVM 17, although I see looking at `main` that the same code exists and will have the same problem.
<details>
```
..../llvm-src/lib/Support/APFloat.cpp:127:61: error: 'const llvm::fltSemantics{15, -14, 11, 16, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semIEEEhalf = {15, -14, 11, 16};
^
..../llvm-src/lib/Support/APFloat.cpp:128:60: error: 'const llvm::fltSemantics{127, -126, 8, 16, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semBFloat = {127, -126, 8, 16};
^
..../llvm-src/lib/Support/APFloat.cpp:129:65: error: 'const llvm::fltSemantics{127, -126, 24, 32, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semIEEEsingle = {127, -126, 24, 32};
^
..../llvm-src/lib/Support/APFloat.cpp:130:67: error: 'const llvm::fltSemantics{1023, -1022, 53, 64, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semIEEEdouble = {1023, -1022, 53, 64};
^
..../llvm-src/lib/Support/APFloat.cpp:131:69: error: 'const llvm::fltSemantics{16383, -16382, 113, 128, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semIEEEquad = {16383, -16382, 113, 128};
^
..../llvm-src/lib/Support/APFloat.cpp:132:61: error: 'const llvm::fltSemantics{15, -14, 3, 8, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semFloat8E5M2 = {15, -14, 3, 8};
^
..../llvm-src/lib/Support/APFloat.cpp:141:64: error: 'const llvm::fltSemantics{127, -126, 11, 19, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semFloatTF32 = {127, -126, 11, 19};
^
..../llvm-src/lib/Support/APFloat.cpp:142:76: error: 'const llvm::fltSemantics{16383, -16382, 64, 80, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semX87DoubleExtended = {16383, -16382, 64, 80};
^
..../llvm-src/lib/Support/APFloat.cpp:143:53: error: 'const llvm::fltSemantics{0, 0, 0, 0, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semBogus = {0, 0, 0, 0};
^
..../llvm-src/lib/Support/APFloat.cpp:154:66: error: 'const llvm::fltSemantics{-1, 0, 0, 128, IEEE754, IEEE}' is not a constant _expression_
static constexpr fltSemantics semPPCDoubleDouble = {-1, 0, 0, 128};
^
..../llvm-src/lib/Support/APFloat.cpp:181:71: error: 'const llvm::fltSemantics{1023, -969, 106, 128, IEEE754, IEEE}' is not a constant _expression_
53 + 53, 128};
^
[ 25%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Chrono.cpp.o
[ 25%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/COM.cpp.o
[ 25%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.o
..../llvm-src/lib/Support/APFloat.cpp: In instantiation of 'void llvm::detail::IEEEFloat::initFromIEEEAPInt(const llvm::APInt&) [with const llvm::fltSemantics& S = llvm::semIEEEquad]':
..../llvm-src/lib/Support/APFloat.cpp:3818:37: required from here
..../llvm-src/lib/Support/APFloat.cpp:3788:10: error: in argument to unary !
(!significand_mask ||
^~~~~~~~~~~~~~~~~
..../llvm-src/lib/Support/APFloat.cpp: In instantiation of 'void llvm::detail::IEEEFloat::initFromIEEEAPInt(const llvm::APInt&) [with const llvm::fltSemantics& S = llvm::semIEEEdouble]':
..../llvm-src/lib/Support/APFloat.cpp:3822:39: required from here
..../llvm-src/lib/Support/APFloat.cpp:3788:10: error: in argument to unary !
..../llvm-src/lib/Support/APFloat.cpp: In instantiation of 'void llvm::detail::IEEEFloat::initFromIEEEAPInt(const llvm::APInt&) [with const llvm::fltSemantics& S = llvm::semIEEEsingle]':
..../llvm-src/lib/Support/APFloat.cpp:3826:39: required from here
..../llvm-src/lib/Support/APFloat.cpp:3788:10: error: in argument to unary !
..../llvm-src/lib/Support/APFloat.cpp: In instantiation of 'void llvm::detail::IEEEFloat::initFromIEEEAPInt(const llvm::APInt&) [with const llvm::fltSemantics& S = llvm::semBFloat]':
..../llvm-src/lib/Support/APFloat.cpp:3830:35: required from here
..../llvm-src/lib/Support/APFloat.cpp:3788:10: error: in argument to unary !
..../llvm-src/lib/Support/APFloat.cpp: In instantiation of 'void llvm::detail::IEEEFloat::initFromIEEEAPInt(const llvm::APInt&) [with const llvm::fltSemantics& S = llvm::semIEEEhalf]':
..../llvm-src/lib/Support/APFloat.cpp:3834:37: required from here
..../llvm-src/lib/Support/APFloat.cpp:3788:10: error: in argument to unary !
..../llvm-src/lib/Support/APFloat.cpp: In instantiation of 'void llvm::detail::IEEEFloat::initFromIEEEAPInt(const llvm::APInt&) [with const llvm::fltSemantics& S = llvm::semFloat8E5M2]':
..../llvm-src/lib/Support/APFloat.cpp:3838:39: required from here
..../llvm-src/lib/Support/APFloat.cpp:3788:10: error: in argument to unary !
..../llvm-src/lib/Support/APFloat.cpp: In instantiation of 'void llvm::detail::IEEEFloat::initFromIEEEAPInt(const llvm::APInt&) [with const llvm::fltSemantics& S = llvm::semFloatTF32]':
..../llvm-src/lib/Support/APFloat.cpp:3858:38: required from here
..../llvm-src/lib/Support/APFloat.cpp:3788:10: error: in argument to unary !
[ 25%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o
```
</details>
I can reproduce this reliably outside of LLVM with GCC 8.1 and 8.2, this seems to be isolated to these versions as GCC 7.5 and GCC 8.3 both work. See https://godbolt.org/z/7d68GK45n. I can make this work again by casting to and from an int, see https://godbolt.org/z/qTP3G31v8.
I also confirmed that this fix works in LLVM using the following patch.
```
--- a/llvm-src/lib/Support/APFloat.cpp
+++ b/llvm-src/lib/Support/APFloat.cpp
@@ -112,9 +112,9 @@ struct fltSemantics {
/* Number of bits actually used in the semantics. */
unsigned int sizeInBits;
- fltNonfiniteBehavior nonFiniteBehavior = fltNonfiniteBehavior::IEEE754;
+ fltNonfiniteBehavior nonFiniteBehavior = fltNonfiniteBehavior(int(fltNonfiniteBehavior::IEEE754));
- fltNanEncoding nanEncoding = fltNanEncoding::IEEE;
+ fltNanEncoding nanEncoding = fltNanEncoding(int(fltNanEncoding::IEEE));
// Returns true if any number described by this semantics can be precisely
// represented by the specified semantics. Does not take into account
// the value of fltNonfiniteBehavior.
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs