Skip to content

Commit

Permalink
Hotfix for K LLVM backend update (#869)
Browse files Browse the repository at this point in the history
This PR is a hotfix for a
[broken](runtimeverification/k#3728) backend
update job.

When using the new [inlined version of
`llvm-kompile`](#814),
we were incorrectly using the result of `sys::getDefaultTargetTriple()`
as our target for machine code emission, rather than the consistent
value selected by running Clang on an empty input file.

On newer versions of macOS, this produces warnings like:
```
ld: warning: object file (tmp.1YutNb2k5B.o) was built for newer macOS version (14.0) than being linked (10.12)
```
when running `llvm-kompile`. These warnings were silently absorbed by CI
as they are just warnings, but they are a) noisy and b) break the K test
suite when grepping for error messages in failed compilations (`kompile
... 2>&1 | grep ...`).

The fix is just to use our existing technique for target triple
selection in the one place we weren't previously.

Additionally, the PR makes two small related changes:
* Add conditional compilation guards for some LLVM headers that give
deprecation warnings in LLVM 17
* Catch future errors of this kind in the backend CI by ensuring that
`llvm-kompile` is silent and doesn't pollute `stderr` with extra output
when it runs successfully
  • Loading branch information
Baltoli authored Oct 19, 2023
1 parent ec3db0e commit 42e1168
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/codegen/ApplyPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
#endif

#include <llvm/IR/LegacyPassManager.h>

#if LLVM_VERSION_MAJOR >= 17
#include <llvm/TargetParser/Host.h>
#include <llvm/TargetParser/SubtargetFeature.h>
#else
#include <llvm/MC/SubtargetFeature.h>
#include <llvm/Support/Host.h>
#endif

#include <llvm/Pass.h>
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/Host.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
#include <llvm/Transforms/Scalar.h>
Expand Down Expand Up @@ -73,7 +80,7 @@ void generate_object_file(llvm::Module &mod, llvm::raw_ostream &os) {
}
#endif

auto triple = sys::getDefaultTargetTriple();
auto triple = "@BACKEND_TARGET_TRIPLE@";
mod.setTargetTriple(triple);

auto error = std::string{};
Expand Down
3 changes: 2 additions & 1 deletion lib/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
configure_file(CreateTerm.cpp CreateTerm.cpp @ONLY)
configure_file(ApplyPasses.cpp ApplyPasses.cpp @ONLY)

add_library(Codegen
${CMAKE_CURRENT_BINARY_DIR}/CreateTerm.cpp
ApplyPasses.cpp
${CMAKE_CURRENT_BINARY_DIR}/ApplyPasses.cpp
CreateStaticTerm.cpp
Debug.cpp
Decision.cpp
Expand Down
8 changes: 7 additions & 1 deletion test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ def one_line(s):

config.substitutions.extend([
('%kompile', 'llvm-kompile-testing'),
('%interpreter', '%kompile %s main -o %t.interpreter'),
('%interpreter', one_line('''
output=$(%kompile %s main -o %t.interpreter 2>&1)
if [[ -n "$output" ]]; then
echo "llvm-kompile error or warning: $output"
exit 1
fi
''')),
('%search-interpreter', '%kompile %s search -o %t.interpreter'),
('%convert-input', '%kore-convert %test-input -o %t.bin'),
('%strip-binary', 'kore-strip'),
Expand Down

0 comments on commit 42e1168

Please sign in to comment.