The GCC and LLVM communities continually perform a remarkable feat by implementing compiler behavior in accordance with the complexities of the C++ Standard. But does that mean developers can blindly trust these two open-source compilers? We put SuperTest to work to answer this question and identified a multitude of discrepancies in the compilers’ operation. Here are five of them, which we presented at emBO++.

The following bugs were discovered during the routine development of our SuperTest test suite. More precisely, they were identified after investigating inconsistencies in the tool output between GCC and Clang during test runs.

Bug #1: Double-type discrepancy. In GCC 13.2 there’s an apparent differentiation in the treatment and representation of two identical double-type variables – an inconsistency that could prove problematic during floating-point arithmetic operations.

Bug #2: Boolean vector hash weakness. Clang’s hash function for boolean vectors has a weakness. It was shown to have low collision resistance and thus deemed unsuitable for safety- and security-critical applications.

Bug #3: Permitted UB in constant expressions. GCC compiles source code with a core constant expression possessing undefined behavior and fails to report any errors. This violates the specification’s declaration that an expression e is a core constant expression unless its evaluation has an operation that would have undefined behavior.

Bug #4: Non-bool-convertible template values accepted. During the invocation of the std::conjunction<> class template, both GCC and Clang erroneously allow traits with values that are non-convertible to boolean. This directly contradicts the C++ Standard, which explicitly states that each template argument shall have a value that is convertible to boolean.

Bug #5: Allowing forbidden specifiers. Use of the constexpr specifier in an explicit instantiation of a variable template is permitted in Clang, but forbidden in the language specification.

Although the aforementioned bugs have been exclusively determined using open-source compilers, errors like these also exist in proprietary compilers.

These bugs demonstrate how unquestioning reliance on open-source compiler tools is potentially dangerous. They bolster the significance and added value of employing SuperTest, the world’s leading compiler test and validation suite, to establish confidence in specified C++ functionality.

Ahmed Abdulbaki Ibrahim, Software Engineer at Solid Sands

“Compiler Black-Box Testing and Peculiar Bugs Encountered”


Subscribe to our monthly blog!