Author: Thurston Dang
Date: 2025-04-17T15:14:52-07:00
New Revision: 20cd74a1c1555385e65d26ff22de7ef75fcb4090

URL: 
https://github.com/llvm/llvm-project/commit/20cd74a1c1555385e65d26ff22de7ef75fcb4090
DIFF: 
https://github.com/llvm/llvm-project/commit/20cd74a1c1555385e65d26ff22de7ef75fcb4090.diff

LOG: [sanitizer] Apply AlwaysIn/Out in parseSanitizeArgs (#129405)

For backwards compatibility, `parseSanitizeArgs`/`parseSanitizeTrapArgs` had an 
incomplete refactoring in
https://github.com/llvm/llvm-project/pull/119819, in order to accommodate the 
special case of vptr in -fsanitize=undefined and its interaction with 
-fsanitize-trap=undefined. Now that vptr is no longer part of 
-fsanitize=undefined (https://github.com/llvm/llvm-project/pull/121115), this 
patch changes parseSanitizeArgs to apply the AlwaysIn/Out invariants in 
parseSanitizeArgs, which allows simplifying calls to parseSanitizeArgs.

This is not quite NFC: it changes the error message of -fsanitize-trap=vptr.

Added: 
    

Modified: 
    clang/lib/Driver/SanitizerArgs.cpp
    clang/test/Driver/fsanitize.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index ee151d5c68b85..f27cb813012f2 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -262,11 +262,8 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
 }
 
 // Computes the sanitizer mask as:
-//     Default + Arguments (in or out)
+//     Default + Arguments (in or out) + AlwaysIn - AlwaysOut
 // with arguments parsed from left to right.
-//
-// Error messages are printed if the AlwaysIn or AlwaysOut invariants are
-// violated, but the caller must enforce these invariants themselves.
 static SanitizerMask
 parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
                   bool DiagnoseErrors, SanitizerMask Default,
@@ -316,6 +313,9 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList 
&Args,
     }
   }
 
+  Output |= AlwaysIn;
+  Output &= ~AlwaysOut;
+
   return Output;
 }
 
@@ -325,10 +325,6 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
   SanitizerMask AlwaysTrap; // Empty
   SanitizerMask NeverTrap = ~(setGroupBits(TrappingSupported));
 
-  // N.B. We do *not* enforce NeverTrap. This maintains the behavior of
-  // '-fsanitize=undefined -fsanitize-trap=undefined'
-  // (clang/test/Driver/fsanitize.c ), which is that vptr is not enabled at all
-  // (not even in recover mode) in order to avoid the need for a ubsan runtime.
   return parseSanitizeArgs(D, Args, DiagnoseErrors, TrappingDefault, 
AlwaysTrap,
                            NeverTrap, options::OPT_fsanitize_trap_EQ,
                            options::OPT_fno_sanitize_trap_EQ);
@@ -727,8 +723,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
       D, Args, DiagnoseErrors, RecoverableByDefault, AlwaysRecoverable,
       Unrecoverable, options::OPT_fsanitize_recover_EQ,
       options::OPT_fno_sanitize_recover_EQ);
-  RecoverableKinds |= AlwaysRecoverable;
-  RecoverableKinds &= ~Unrecoverable;
   RecoverableKinds &= Kinds;
 
   TrappingKinds &= Kinds;

diff  --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 8652f1d875e68..c154e339941f2 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -149,7 +149,7 @@
 // CHECK-FSANITIZE-SHIFT-PARTIAL: "-fsanitize=shift-exponent"
 
 // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=vptr 
-fsanitize-trap=vptr %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-VPTR-TRAP-UNDEF
-// CHECK-VPTR-TRAP-UNDEF: error: invalid argument '-fsanitize=vptr' not 
allowed with '-fsanitize-trap=undefined'
+// CHECK-VPTR-TRAP-UNDEF: error: unsupported argument 'vptr' to option 
'-fsanitize-trap='
 
 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=vptr 
-fsanitize-undefined-trap-on-error %s -###
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to