From 134f27df2695de086472ce70b1197b622fabc147 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Wed, 16 Aug 2023 04:01:11 +0800 Subject: Disable strict aliasing for gcc (#3105) Co-authored-by: Yong He --- source/compiler-core/slang-gcc-compiler-util.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source') diff --git a/source/compiler-core/slang-gcc-compiler-util.cpp b/source/compiler-core/slang-gcc-compiler-util.cpp index c4354f40e..d8df9714a 100644 --- a/source/compiler-core/slang-gcc-compiler-util.cpp +++ b/source/compiler-core/slang-gcc-compiler-util.cpp @@ -470,6 +470,11 @@ static SlangResult _parseGCCFamilyLine(SliceAllocator& allocator, const UnownedS cmdLine.addArg("-std=c++17"); } + // Our generated code very often casts between dissimilar types with the + // knowledge that they have the same representation. This is strictly + // speaking UB, and GCC 10+ is happy to take advantage of this, stop it. + cmdLine.addArg("-fno-strict-aliasing"); + // TODO(JS): Here we always set -m32 on x86. It could be argued it is only necessary when creating a shared library // but if we create an object file, we don't know what to choose because we don't know what final usage is. // It could also be argued that the platformKind could define the actual desired target - but as it stands -- cgit v1.2.3