-
Notifications
You must be signed in to change notification settings - Fork 12.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang] Fix seg fault CodeGenAction::executeAction()
#78269
Conversation
@llvm/pr-subscribers-flang-driver Author: Kareem Ergawy (ergawy) ChangesIf Full diff: https://github.com/llvm/llvm-project/pull/78269.diff 1 Files Affected:
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 74e3992d5ab62ba..65c4df7388f97b2 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1202,6 +1202,11 @@ void CodeGenAction::executeAction() {
if (!llvmModule)
generateLLVMIR();
+ // If generating the LLVM module failed, abort! No need for further error
+ // reporting since generateLLVMIR() does this already.
+ if (!llvmModule)
+ return;
+
// Set the triple based on the targetmachine (this comes compiler invocation
// and the command-line target option if specified, or the default if not
// given on the command-line).
|
Note that I came across this issue while testing:
For this input:
Now, I get this error (without the seg fault):
I am currently looking into this issue and will hopefully open a separate PR. Edit: this happens because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
It would be good to add a diagnostic and a test - perhaps trying compiling a "broken" MLIR file?
Thanks for the reply @banach-space. I can try to add a unit test (I see there is none for the flang |
+1 :) |
7cdb558
to
9f3f129
Compare
Done! |
9f3f129
to
ae81413
Compare
If `generateLLVMIR()` fails, we still continue using the module we failed to generate which causes a seg fault if LLVM code-gen failed for some reason or another. This commit fixes this issue.
ae81413
to
023815c
Compare
Ping! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clever - love this approach :)
LGTM, thank you!
…" (#78667) This reverts commit 99cae9a. Temporarily until I reproduce and fix a linker issue: ``` FAILED: tools/flang/unittests/Frontend/FlangFrontendTests ... /usr/bin/ld: tools/flang/unittests/Frontend/CMakeFiles/FlangFrontendTests.dir/CodeGenActionTest.cpp.o: undefined reference to symbol '_ZN4llvm11LLVMContextC1Ev' /usr/bin/ld: /work1/omp-nightly/build/git/trunk18.0/build/llvm-project/lib/libLLVMCore.so.18git: error adding symbols: DSO missing from command line ```
llvm#78269)" (llvm#78667)" This reverts commit 4fc7506. Re-applies PR llvm#78269 and adds LLVM and MLIR dependencies that were missed in the PR. The missing libs were: `LLVMCore` & `MLIRIR`.
If `generateLLVMIR()` fails, we still continue using the module we failed to generate which causes a seg fault if LLVM code-gen failed for some reason or another. This commit fixes this issue. Re-applies PR #78269 and adds LLVM and MLIR dependencies that were missed in the PR. The missing libs were: `LLVMCore` & `MLIRIR`. This reverts commit 4fc7506.
Provides some context for failing to generate LLVM IR for `target enter|exit|update` directives when `nowait` is provided. This is directly helpful for flang users since they would get this error message if they tried to use `nowait`. Before that we had a very generic message. This is a follow-up to #78269, please only review the latest commit (the one with the same commit message as the PR title).
If
generateLLVMIR()
fails, we still continue using the module we failed to generate which causes a seg fault if LLVM code-gen failed for some reason or another. This commit fixes this issue.