[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-13 Thread via cfe-commits

github-actions[bot] wrote:



@j39m Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-13 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka closed 
https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-13 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka auto_merge_enabled 
https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-13 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka approved this pull request.

I suspect this new functionality is unnecessary micromanagement.
But I don't expect issues from having that.
So LGTM

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-13 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.


https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-12 Thread via cfe-commits

https://github.com/j39m updated https://github.com/llvm/llvm-project/pull/170822

>From 30462f19f6ba2bf53eb6440dff018c40282bf3fd Mon Sep 17 00:00:00 2001
From: Kalvin Lee 
Date: Fri, 5 Dec 2025 17:37:29 +0900
Subject: [PATCH 1/6] Add fine-grained `__has_feature()` cutout

This is a follow-up to pull 148323. It mints
`-fsanitize-ignore-for-ubsan-feature=...`, accepting a list of (UBSan)
sanitizers that should not cause
`__has_feature(undefined_behavior_sanitizer)` to evaluate true.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  1 +
 clang/include/clang/Basic/Features.def|  2 +-
 clang/include/clang/Basic/LangOptions.h   |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/include/clang/Options/Options.td|  8 +
 clang/lib/Driver/SanitizerArgs.cpp| 29 ++
 clang/lib/Frontend/CompilerInvocation.cpp | 15 ++
 ...s_feature_undefined_behavior_sanitizer.cpp | 30 +++
 8 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index aeffe96e806bd..9e5ca9f76397b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,7 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_not_a_ubsan_sanitizer : Error<"not a UBSan sanitizer: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 0e91b42a132c1..52dd3a72392ee 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -53,7 +53,7 @@ FEATURE(memtag_globals,
 LangOpts.Sanitize.has(SanitizerKind::MemtagGlobals))
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
-LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined & 
~LangOpts.UBSanFeatureSuppressedSanitize.Mask))
 FEATURE(undefined_behavior_sanitizer_finegrained_feature_checks, true)
 // These are all part of undefined_behavior_sanitizer:
 FEATURE(alignment_sanitizer,
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 3f042f8ddb5a1..66fe01e877cb1 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause
+  /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
+  SanitizerSet UBSanFeatureSuppressedSanitize;
 
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 84fb66e16bee3..aa8aa9be287c6 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -28,6 +28,7 @@ class SanitizerArgs {
   SanitizerSet MergeHandlers;
   SanitizerMaskCutoffs SkipHotCutoffs;
   SanitizerSet AnnotateDebugInfo;
+  SanitizerSet SuppressUBSanFeature;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index c6841937c8d39..84243ad80f2a1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2404,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<
+  "Prevents `__has_feature(undefined_behavior_sanitizer)` from "
+  "evaluating true for "
+  "these UBSan checks. See user manual for available UBSan checks">;
 
 def fsanitize_ignorelist_EQ : Joined<["-"], "fsanitize-ignorelist=">,
   Group, HelpText<"Path to ignorelist file for sanitizers">;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index be068b2381d06..08db579626437 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -408,6 +408,8 @@ SanitizerArgs::Sani

[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-12 Thread via cfe-commits


@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause

j39m wrote:

Pushing a fixup commit to incorporate...

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-06 Thread Florian Mayer via cfe-commits


@@ -2421,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,

fmayer wrote:

Because we want to be able to say which features do not count as UBSan enabled.

So we can say: "we do not consider array-bounds a sanitizer", and then when we 
_only_ enable that, the UBSan macro is not set.

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-06 Thread Vitaly Buka via cfe-commits


@@ -2421,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,

vitalybuka wrote:

I can see that #148323 breaks some pre-existing code.
If it's not large scale issue, it's probably does not worse of a new flag.

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-06 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2026-01-06 Thread Vitaly Buka via cfe-commits


@@ -2421,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,

vitalybuka wrote:

why do we need the flag?

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-26 Thread Florian Mayer via cfe-commits


@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause

fmayer wrote:

I don't think this is correct? Isn't it "Set of  (UBSan) sanitizers that when 
enabled do not cause ..."?

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-17 Thread via cfe-commits


@@ -277,6 +277,7 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_not_a_ubsan_sanitizer : Error<"not a UBSan sanitizer: '%0'">;

j39m wrote:

Thanks - fixed.

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-17 Thread via cfe-commits

https://github.com/j39m updated https://github.com/llvm/llvm-project/pull/170822

>From 30462f19f6ba2bf53eb6440dff018c40282bf3fd Mon Sep 17 00:00:00 2001
From: Kalvin Lee 
Date: Fri, 5 Dec 2025 17:37:29 +0900
Subject: [PATCH 1/5] Add fine-grained `__has_feature()` cutout

This is a follow-up to pull 148323. It mints
`-fsanitize-ignore-for-ubsan-feature=...`, accepting a list of (UBSan)
sanitizers that should not cause
`__has_feature(undefined_behavior_sanitizer)` to evaluate true.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  1 +
 clang/include/clang/Basic/Features.def|  2 +-
 clang/include/clang/Basic/LangOptions.h   |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/include/clang/Options/Options.td|  8 +
 clang/lib/Driver/SanitizerArgs.cpp| 29 ++
 clang/lib/Frontend/CompilerInvocation.cpp | 15 ++
 ...s_feature_undefined_behavior_sanitizer.cpp | 30 +++
 8 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index aeffe96e806bd..9e5ca9f76397b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,7 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_not_a_ubsan_sanitizer : Error<"not a UBSan sanitizer: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 0e91b42a132c1..52dd3a72392ee 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -53,7 +53,7 @@ FEATURE(memtag_globals,
 LangOpts.Sanitize.has(SanitizerKind::MemtagGlobals))
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
-LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined & 
~LangOpts.UBSanFeatureSuppressedSanitize.Mask))
 FEATURE(undefined_behavior_sanitizer_finegrained_feature_checks, true)
 // These are all part of undefined_behavior_sanitizer:
 FEATURE(alignment_sanitizer,
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 3f042f8ddb5a1..66fe01e877cb1 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause
+  /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
+  SanitizerSet UBSanFeatureSuppressedSanitize;
 
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 84fb66e16bee3..aa8aa9be287c6 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -28,6 +28,7 @@ class SanitizerArgs {
   SanitizerSet MergeHandlers;
   SanitizerMaskCutoffs SkipHotCutoffs;
   SanitizerSet AnnotateDebugInfo;
+  SanitizerSet SuppressUBSanFeature;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index c6841937c8d39..84243ad80f2a1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2404,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<
+  "Prevents `__has_feature(undefined_behavior_sanitizer)` from "
+  "evaluating true for "
+  "these UBSan checks. See user manual for available UBSan checks">;
 
 def fsanitize_ignorelist_EQ : Joined<["-"], "fsanitize-ignorelist=">,
   Group, HelpText<"Path to ignorelist file for sanitizers">;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index be068b2381d06..08db579626437 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -408,6 +408,8 @@ SanitizerArgs::Sani

[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-16 Thread via cfe-commits

https://github.com/j39m updated https://github.com/llvm/llvm-project/pull/170822

>From 30462f19f6ba2bf53eb6440dff018c40282bf3fd Mon Sep 17 00:00:00 2001
From: Kalvin Lee 
Date: Fri, 5 Dec 2025 17:37:29 +0900
Subject: [PATCH 1/4] Add fine-grained `__has_feature()` cutout

This is a follow-up to pull 148323. It mints
`-fsanitize-ignore-for-ubsan-feature=...`, accepting a list of (UBSan)
sanitizers that should not cause
`__has_feature(undefined_behavior_sanitizer)` to evaluate true.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  1 +
 clang/include/clang/Basic/Features.def|  2 +-
 clang/include/clang/Basic/LangOptions.h   |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/include/clang/Options/Options.td|  8 +
 clang/lib/Driver/SanitizerArgs.cpp| 29 ++
 clang/lib/Frontend/CompilerInvocation.cpp | 15 ++
 ...s_feature_undefined_behavior_sanitizer.cpp | 30 +++
 8 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index aeffe96e806bd..9e5ca9f76397b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,7 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_not_a_ubsan_sanitizer : Error<"not a UBSan sanitizer: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 0e91b42a132c1..52dd3a72392ee 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -53,7 +53,7 @@ FEATURE(memtag_globals,
 LangOpts.Sanitize.has(SanitizerKind::MemtagGlobals))
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
-LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined & 
~LangOpts.UBSanFeatureSuppressedSanitize.Mask))
 FEATURE(undefined_behavior_sanitizer_finegrained_feature_checks, true)
 // These are all part of undefined_behavior_sanitizer:
 FEATURE(alignment_sanitizer,
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 3f042f8ddb5a1..66fe01e877cb1 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause
+  /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
+  SanitizerSet UBSanFeatureSuppressedSanitize;
 
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 84fb66e16bee3..aa8aa9be287c6 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -28,6 +28,7 @@ class SanitizerArgs {
   SanitizerSet MergeHandlers;
   SanitizerMaskCutoffs SkipHotCutoffs;
   SanitizerSet AnnotateDebugInfo;
+  SanitizerSet SuppressUBSanFeature;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index c6841937c8d39..84243ad80f2a1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2404,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<
+  "Prevents `__has_feature(undefined_behavior_sanitizer)` from "
+  "evaluating true for "
+  "these UBSan checks. See user manual for available UBSan checks">;
 
 def fsanitize_ignorelist_EQ : Joined<["-"], "fsanitize-ignorelist=">,
   Group, HelpText<"Path to ignorelist file for sanitizers">;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index be068b2381d06..08db579626437 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -408,6 +408,8 @@ SanitizerArgs::Sani

[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-14 Thread via cfe-commits

j39m wrote:

I've been waiting on the `build and test {linux,windows}` steps for a few days 
now. Is there something I need to do to make them resolve?

I will still need a hint on what build target to use to repro the failure in my 
tree.

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-10 Thread via cfe-commits

j39m wrote:

I'm unable to reproduce the test failure in my checkout. I tried mimicking a 
subset of `monolithic-linux.sh`, but neither of `check-clang` or 
`check-clang-tools` produces any failures that I can see.

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-10 Thread via cfe-commits

https://github.com/j39m updated https://github.com/llvm/llvm-project/pull/170822

>From 30462f19f6ba2bf53eb6440dff018c40282bf3fd Mon Sep 17 00:00:00 2001
From: Kalvin Lee 
Date: Fri, 5 Dec 2025 17:37:29 +0900
Subject: [PATCH 1/3] Add fine-grained `__has_feature()` cutout

This is a follow-up to pull 148323. It mints
`-fsanitize-ignore-for-ubsan-feature=...`, accepting a list of (UBSan)
sanitizers that should not cause
`__has_feature(undefined_behavior_sanitizer)` to evaluate true.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  1 +
 clang/include/clang/Basic/Features.def|  2 +-
 clang/include/clang/Basic/LangOptions.h   |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/include/clang/Options/Options.td|  8 +
 clang/lib/Driver/SanitizerArgs.cpp| 29 ++
 clang/lib/Frontend/CompilerInvocation.cpp | 15 ++
 ...s_feature_undefined_behavior_sanitizer.cpp | 30 +++
 8 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index aeffe96e806bd..9e5ca9f76397b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,7 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_not_a_ubsan_sanitizer : Error<"not a UBSan sanitizer: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 0e91b42a132c1..52dd3a72392ee 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -53,7 +53,7 @@ FEATURE(memtag_globals,
 LangOpts.Sanitize.has(SanitizerKind::MemtagGlobals))
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
-LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined & 
~LangOpts.UBSanFeatureSuppressedSanitize.Mask))
 FEATURE(undefined_behavior_sanitizer_finegrained_feature_checks, true)
 // These are all part of undefined_behavior_sanitizer:
 FEATURE(alignment_sanitizer,
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 3f042f8ddb5a1..66fe01e877cb1 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause
+  /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
+  SanitizerSet UBSanFeatureSuppressedSanitize;
 
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 84fb66e16bee3..aa8aa9be287c6 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -28,6 +28,7 @@ class SanitizerArgs {
   SanitizerSet MergeHandlers;
   SanitizerMaskCutoffs SkipHotCutoffs;
   SanitizerSet AnnotateDebugInfo;
+  SanitizerSet SuppressUBSanFeature;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index c6841937c8d39..84243ad80f2a1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2404,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<
+  "Prevents `__has_feature(undefined_behavior_sanitizer)` from "
+  "evaluating true for "
+  "these UBSan checks. See user manual for available UBSan checks">;
 
 def fsanitize_ignorelist_EQ : Joined<["-"], "fsanitize-ignorelist=">,
   Group, HelpText<"Path to ignorelist file for sanitizers">;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index be068b2381d06..08db579626437 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -408,6 +408,8 @@ SanitizerArgs::Sani

[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-09 Thread Florian Mayer via cfe-commits

fmayer wrote:

Please fix test failure

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-09 Thread via cfe-commits

github-actions[bot] wrote:


# :window: Windows x64 Test Results

* 51416 tests passed
* 852 tests skipped
* 1 test failed

## Failed Tests
(click on a test name to see its output)

### Clang

Clang.Lexer/has_feature_undefined_behavior_sanitizer.cpp

```
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -E -target 
x86_64-unknown-linux-gnu -fsanitize=undefined 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
 -o - | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe 
--check-prefix=CHECK-UBSAN 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -E 
-target x86_64-unknown-linux-gnu -fsanitize=undefined 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
 -o -
# note: command had no output on stdout or stderr
# executed command: 
'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 
--check-prefix=CHECK-UBSAN 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
# note: command had no output on stdout or stderr
# RUN: at line 2
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -E -target 
x86_64-unknown-linux-gnu -fsanitize=alignment 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
 -o - | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe 
--check-prefixes=CHECK-UBSAN,CHECK-ALIGNMENT 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -E 
-target x86_64-unknown-linux-gnu -fsanitize=alignment 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
 -o -
# note: command had no output on stdout or stderr
# executed command: 
'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 
--check-prefixes=CHECK-UBSAN,CHECK-ALIGNMENT 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
# note: command had no output on stdout or stderr
# RUN: at line 3
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -E -target 
x86_64-unknown-linux-gnu -fsanitize=bool 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
 -o - | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe 
--check-prefixes=CHECK-UBSAN,CHECK-BOOL 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -E 
-target x86_64-unknown-linux-gnu -fsanitize=bool 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
 -o -
# note: command had no output on stdout or stderr
# executed command: 
'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 
--check-prefixes=CHECK-UBSAN,CHECK-BOOL 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
# note: command had no output on stdout or stderr
# RUN: at line 4
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -E -target 
x86_64-unknown-linux-gnu -fsanitize=builtin 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
 -o - | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe 
--check-prefixes=CHECK-UBSAN,CHECK-BUILTIN 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -E 
-target x86_64-unknown-linux-gnu -fsanitize=builtin 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
 -o -
# note: command had no output on stdout or stderr
# executed command: 
'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 
--check-prefixes=CHECK-UBSAN,CHECK-BUILTIN 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
# note: command had no output on stdout or stderr
# RUN: at line 5
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -E -target 
x86_64-unknown-linux-gnu -fsanitize=array-bounds 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
 -o - | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe 
--check-prefixes=CHECK-UBSAN,CHECK-ARRAY-BOUNDS 
C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -E 
-target x86_64-unknown-linux-gnu -fsanitize=array-bounds 
'C:\_work\llvm-project\llvm-project\clang\test\Lexer\has_feature_undefined_behavior_sanitizer.cpp'
 -o -
# note: command had no output on stdout or s

[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-08 Thread via cfe-commits


@@ -736,6 +743,22 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   // -f(-no)sanitize=leak should change whether leak detection is enabled by
   // default in ASan?
 
+  // Error if a non-UBSan sanitizer is passed to
+  // `-fsanitize-ignore-for-ubsan-feature=`.
+  //
+  // `shift` is a `SANITIZER_GROUP()`, and so is expanded into its constituents
+  // by `expandSanitizerGroups()` above, though the physical bit is not 
included
+  // in `SanitizerKind::Undefined`.
+  const SanitizerMask not_ubsan_mask =
+  IgnoreForUbsanFeature &
+  ~(SanitizerKind::Undefined | SanitizerKind::ShiftGroup);

j39m wrote:

Understood --- removed all this in the follow-up.

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-08 Thread via cfe-commits


@@ -3973,6 +3980,10 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
 Opts.PIE = Args.hasArg(OPT_pic_is_pie);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
 Diags, Opts.Sanitize);
+parseSanitizerKinds(
+"-fsanitize-ignore-for-ubsan-feature=",
+Args.getAllArgValues(OPT_fsanitize_ignore_for_ubsan_feature_EQ), Diags,
+Opts.UBSanFeatureSuppressedSanitize);

j39m wrote:

Thanks --- fixed in a follow-up.

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-08 Thread Florian Mayer via cfe-commits


@@ -736,6 +743,22 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   // -f(-no)sanitize=leak should change whether leak detection is enabled by
   // default in ASan?
 
+  // Error if a non-UBSan sanitizer is passed to
+  // `-fsanitize-ignore-for-ubsan-feature=`.
+  //
+  // `shift` is a `SANITIZER_GROUP()`, and so is expanded into its constituents
+  // by `expandSanitizerGroups()` above, though the physical bit is not 
included
+  // in `SanitizerKind::Undefined`.
+  const SanitizerMask not_ubsan_mask =
+  IgnoreForUbsanFeature &
+  ~(SanitizerKind::Undefined | SanitizerKind::ShiftGroup);

fmayer wrote:

hmmm. not sure this gymnastics are worth if for the warning

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-08 Thread Florian Mayer via cfe-commits


@@ -3973,6 +3980,10 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
 Opts.PIE = Args.hasArg(OPT_pic_is_pie);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
 Diags, Opts.Sanitize);
+parseSanitizerKinds(
+"-fsanitize-ignore-for-ubsan-feature=",
+Args.getAllArgValues(OPT_fsanitize_ignore_for_ubsan_feature_EQ), Diags,
+Opts.UBSanFeatureSuppressedSanitize);

fmayer wrote:

I would use consistent terminology regarding `ignore` or `suppress` for the 
flag and the opt

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-07 Thread via cfe-commits

j39m wrote:

CC @fmayer (for general observation from afar)

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kalvin (j39m)


Changes

This is a follow-up to pull 148323. It mints
`-fsanitize-ignore-for-ubsan-feature=...`, accepting a list of (UBSan) 
sanitizers that should not cause
`__has_feature(undefined_behavior_sanitizer)` to evaluate true.

---
Full diff: https://github.com/llvm/llvm-project/pull/170822.diff


8 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+1) 
- (modified) clang/include/clang/Basic/Features.def (+1-1) 
- (modified) clang/include/clang/Basic/LangOptions.h (+3) 
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+1) 
- (modified) clang/include/clang/Options/Options.td (+8) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+29) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+15) 
- (modified) clang/test/Lexer/has_feature_undefined_behavior_sanitizer.cpp 
(+30) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index aeffe96e806bd..9e5ca9f76397b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,7 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_not_a_ubsan_sanitizer : Error<"not a UBSan sanitizer: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 0e91b42a132c1..52dd3a72392ee 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -53,7 +53,7 @@ FEATURE(memtag_globals,
 LangOpts.Sanitize.has(SanitizerKind::MemtagGlobals))
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
-LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined & 
~LangOpts.UBSanFeatureSuppressedSanitize.Mask))
 FEATURE(undefined_behavior_sanitizer_finegrained_feature_checks, true)
 // These are all part of undefined_behavior_sanitizer:
 FEATURE(alignment_sanitizer,
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 3f042f8ddb5a1..66fe01e877cb1 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause
+  /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
+  SanitizerSet UBSanFeatureSuppressedSanitize;
 
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 84fb66e16bee3..aa8aa9be287c6 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -28,6 +28,7 @@ class SanitizerArgs {
   SanitizerSet MergeHandlers;
   SanitizerMaskCutoffs SkipHotCutoffs;
   SanitizerSet AnnotateDebugInfo;
+  SanitizerSet SuppressUBSanFeature;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index c6841937c8d39..84243ad80f2a1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2404,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<
+  "Prevents `__has_feature(undefined_behavior_sanitizer)` from "
+  "evaluating true for "
+  "these UBSan checks. See user manual for available UBSan checks">;
 
 def fsanitize_ignorelist_EQ : Joined<["-"], "fsanitize-ignorelist=">,
   Group, HelpText<"Path to ignorelist file for sanitizers">;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index be068b2381d06..08db579626437 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -408,6 +408,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 // unused-argument diagnostics.
   SanitizerMask

[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Kalvin (j39m)


Changes

This is a follow-up to pull 148323. It mints
`-fsanitize-ignore-for-ubsan-feature=...`, accepting a list of (UBSan) 
sanitizers that should not cause
`__has_feature(undefined_behavior_sanitizer)` to evaluate true.

---
Full diff: https://github.com/llvm/llvm-project/pull/170822.diff


8 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+1) 
- (modified) clang/include/clang/Basic/Features.def (+1-1) 
- (modified) clang/include/clang/Basic/LangOptions.h (+3) 
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+1) 
- (modified) clang/include/clang/Options/Options.td (+8) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+29) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+15) 
- (modified) clang/test/Lexer/has_feature_undefined_behavior_sanitizer.cpp 
(+30) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index aeffe96e806bd..9e5ca9f76397b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,7 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_not_a_ubsan_sanitizer : Error<"not a UBSan sanitizer: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 0e91b42a132c1..52dd3a72392ee 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -53,7 +53,7 @@ FEATURE(memtag_globals,
 LangOpts.Sanitize.has(SanitizerKind::MemtagGlobals))
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
-LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined & 
~LangOpts.UBSanFeatureSuppressedSanitize.Mask))
 FEATURE(undefined_behavior_sanitizer_finegrained_feature_checks, true)
 // These are all part of undefined_behavior_sanitizer:
 FEATURE(alignment_sanitizer,
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 3f042f8ddb5a1..66fe01e877cb1 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause
+  /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
+  SanitizerSet UBSanFeatureSuppressedSanitize;
 
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 84fb66e16bee3..aa8aa9be287c6 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -28,6 +28,7 @@ class SanitizerArgs {
   SanitizerSet MergeHandlers;
   SanitizerMaskCutoffs SkipHotCutoffs;
   SanitizerSet AnnotateDebugInfo;
+  SanitizerSet SuppressUBSanFeature;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index c6841937c8d39..84243ad80f2a1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2404,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<
+  "Prevents `__has_feature(undefined_behavior_sanitizer)` from "
+  "evaluating true for "
+  "these UBSan checks. See user manual for available UBSan checks">;
 
 def fsanitize_ignorelist_EQ : Joined<["-"], "fsanitize-ignorelist=">,
   Group, HelpText<"Path to ignorelist file for sanitizers">;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index be068b2381d06..08db579626437 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -408,6 +408,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 // unused-argument diagnostics.
   Saniti

[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-05 Thread via cfe-commits

github-actions[bot] wrote:



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 `@` followed by their GitHub username.

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](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/170822
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add fine-grained `__has_feature()` cutout (PR #170822)

2025-12-05 Thread via cfe-commits

https://github.com/j39m created https://github.com/llvm/llvm-project/pull/170822

This is a follow-up to pull 148323. It mints
`-fsanitize-ignore-for-ubsan-feature=...`, accepting a list of (UBSan) 
sanitizers that should not cause
`__has_feature(undefined_behavior_sanitizer)` to evaluate true.

>From 30462f19f6ba2bf53eb6440dff018c40282bf3fd Mon Sep 17 00:00:00 2001
From: Kalvin Lee 
Date: Fri, 5 Dec 2025 17:37:29 +0900
Subject: [PATCH] Add fine-grained `__has_feature()` cutout

This is a follow-up to pull 148323. It mints
`-fsanitize-ignore-for-ubsan-feature=...`, accepting a list of (UBSan)
sanitizers that should not cause
`__has_feature(undefined_behavior_sanitizer)` to evaluate true.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  1 +
 clang/include/clang/Basic/Features.def|  2 +-
 clang/include/clang/Basic/LangOptions.h   |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/include/clang/Options/Options.td|  8 +
 clang/lib/Driver/SanitizerArgs.cpp| 29 ++
 clang/lib/Frontend/CompilerInvocation.cpp | 15 ++
 ...s_feature_undefined_behavior_sanitizer.cpp | 30 +++
 8 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index aeffe96e806bd..9e5ca9f76397b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,7 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_not_a_ubsan_sanitizer : Error<"not a UBSan sanitizer: '%0'">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 0e91b42a132c1..52dd3a72392ee 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -53,7 +53,7 @@ FEATURE(memtag_globals,
 LangOpts.Sanitize.has(SanitizerKind::MemtagGlobals))
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
-LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined & 
~LangOpts.UBSanFeatureSuppressedSanitize.Mask))
 FEATURE(undefined_behavior_sanitizer_finegrained_feature_checks, true)
 // These are all part of undefined_behavior_sanitizer:
 FEATURE(alignment_sanitizer,
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 3f042f8ddb5a1..66fe01e877cb1 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -441,6 +441,9 @@ class LangOptions : public LangOptionsBase {
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
+  /// Set of enabled (undefined behavior) sanitizers that do not cause
+  /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
+  SanitizerSet UBSanFeatureSuppressedSanitize;
 
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 84fb66e16bee3..aa8aa9be287c6 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -28,6 +28,7 @@ class SanitizerArgs {
   SanitizerSet MergeHandlers;
   SanitizerMaskCutoffs SkipHotCutoffs;
   SanitizerSet AnnotateDebugInfo;
+  SanitizerSet SuppressUBSanFeature;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index c6841937c8d39..84243ad80f2a1 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -2404,6 +2404,14 @@ def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, 
Group,
 "or suspicious behavior. See user manual for 
available checks">;
 def fno_sanitize_EQ : CommaJoined<["-"], "fno-sanitize=">, 
Group,
   Visibility<[ClangOption, CLOption]>;
+def fsanitize_ignore_for_ubsan_feature_EQ
+: CommaJoined<["-"], "fsanitize-ignore-for-ubsan-feature=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<
+  "Prevents `__has_feature(undefined_behavior_sanitizer)` from "
+  "evaluating true for "
+  "these UBSan checks. See user manual for available UBSan checks">;
 
 def fsanitize_ignorelist_EQ : Joined<["-"], "fsanitize-ignorelist=">,
   Group, HelpText<"Path to ignorelist file for sanitizers">;
diff --git a/clang/lib/Driver/Sanitize