-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> #147997
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Anthony Tran (anthonyhatran) ChangesPart of a GSoC 2025 Project Full diff: https://github.com/llvm/llvm-project/pull/147997.diff 2 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 34b6c0d7a8acd..49a8bdf06bda4 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -874,4 +874,9 @@ def warn_drv_openacc_without_cir
: Warning<"OpenACC directives will result in no runtime behavior; use "
"-fclangir to enable runtime effect">,
InGroup<SourceUsesOpenACC>;
+
+def warn_drv_sanitize_trap_mismatch : Warning<
+ "-fsanitize-trap=%0 has no effect because the matching sanitizer is not enabled; "
+ "did you mean to pass \"-fsanitize=%0\" as well?">,
+ InGroup<SanitizeTrapMismatch>;
}
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index f54a830b0103e..a79562cd9c2e0 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1752,3 +1752,6 @@ def ExplicitSpecializationStorageClass : DiagGroup<"explicit-specialization-stor
// A warning for options that enable a feature that is not yet complete
def ExperimentalOption : DiagGroup<"experimental-option">;
+
+// Warnings for sanitizer arguments
+def SanitizeTrapMismatch : DiagGroup<"sanitize-trap-mismatch">;
|
1bcc20d
to
f1bf9b3
Compare
The current -fsanitize-trap behavior is intentional. See I believe Google actually depended on -fsanitize-trap=undefined not leading to warnings/errors when -fsanitize=undefined is not specified. |
@MaskRay i think the intention of this PR was to write up an accompanying RFC. I don't think the linked Discourse thread had consensus on whether this was something we want to change or not (summoning @delcypher) Re-opening for now. |
Yes we aware the current behavior is intentional. That however doesn't mean it's the right behavior. Our intention is to post a corresponding RFC but as part of the RFC we also wanted a sketch patch of what we are proposing so we can be concrete about our proposed alternative. We (myself & @Michael137) are working with a @anthonyhatran a Google Summer of Code mentee to get the sketch patch in good shape and then we will work on an RFC and then post it. Although I understand you have good intentions behind proactively closing the PR please do not close our mentee's PR again. If it's ultimately rejected, we'll do it. |
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.
Looks good for the sketch patch. I have a few minor questions and nits that I've left. Please add a few driver test cases to illustrate how you expect this to work (including a test case that suppresses the warning).
Thank you for your efforts to enhance sanitizers. However, the current implementation aligns with the preferences of many, including GCC contributors who introduced -fsanitize-trap in 2022. Speaking in my capacity as a clang driver maintainer, sanitizer contributor, and GCC committer, gaining consensus to modify -fsanitize-trap to issue warnings or errors seems unlikely, so closing this issue appears to be the appropriate action. The proposed change could serve an educational purpose by illustrating modifications to the driver and sanitizer components. However, pursuing its development within llvm/llvm-project risks causing confusion among contributors. |
This PR is a work-in-progress (WIP) and should not be merged.
This is a sketch PR that will accompany an RFC about changing Clang's behavior handling -
fsanitize-trap=
without the corresponding sanitizer being enabled.[Description will be rewritten later]
Spreading this patch out across multiple commits for better practice.
Part of a GSoC 2025 Project