llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: Balázs Benics (steakhal)

<details>
<summary>Changes</summary>

#<!-- -->239729 inserted ReturnAlignmentAssumption before BoundsSafety in 
LIST_SANITIZER_CHECKS, shifting BoundsSafety from 0x19 to 0x1a. The handler 
value is the llvm.ubsantrap kind, and 0x19 is part of the -fbounds-safety trap 
ABI (`brk #<!-- -->0x5519` on arm64, `ud1l 0x19(%eax), %eax` on x86_64) that 
debuggers decode.

Move ReturnAlignmentAssumption after BoundsSafety, add a static_assert pinning 
BoundsSafety to 0x19, and note that new checks must be appended at the end of 
the list. ReturnAlignmentAssumption becomes 0x1a, so update the tests from 
#<!-- -->239729 that check its trap kind.

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


5 Files Affected:

- (modified) clang/lib/CodeGen/SanitizerHandler.h (+10-5) 
- (modified) 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
 (+1-1) 
- (modified) 
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
 (+1-1) 
- (modified) 
clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp
 (+1-1) 
- (modified) 
clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function.cpp
 (+1-1) 


``````````diff
diff --git a/clang/lib/CodeGen/SanitizerHandler.h 
b/clang/lib/CodeGen/SanitizerHandler.h
index 8e70839ca42ad..d1797ef111c05 100644
--- a/clang/lib/CodeGen/SanitizerHandler.h
+++ b/clang/lib/CodeGen/SanitizerHandler.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H
 #define LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H
 
+// To add new checks, append them to the end of this list.
 #define LIST_SANITIZER_CHECKS                                                  
\
   SANITIZER_CHECK(AddOverflow, add_overflow, 0, "Integer addition overflowed") 
\
   SANITIZER_CHECK(BuiltinUnreachable, builtin_unreachable, 0,                  
\
@@ -70,12 +71,11 @@
   SANITIZER_CHECK(                                                             
\
       VLABoundNotPositive, vla_bound_not_positive, 0,                          
\
       "Variable length array bound evaluates to non-positive value")           
\
+  /* BoundsSafety Msg is empty because it is not considered part of UBSan; */  
\
+  /* therefore, no trap reason is emitted for this case. */                    
\
+  SANITIZER_CHECK(BoundsSafety, bounds_safety, 0, "")                          
\
   SANITIZER_CHECK(ReturnAlignmentAssumption, return_alignment_assumption, 0,   
\
-                  "Alignment assumption violated")                             
\
-  SANITIZER_CHECK(BoundsSafety, bounds_safety, 0,                              
\
-                  "") // BoundsSafety Msg is empty because it is not considered
-                      // part of UBSan; therefore, no trap reason is emitted 
for
-                      // this case.
+                  "Alignment assumption violated")
 
 enum SanitizerHandler {
 #define SANITIZER_CHECK(Enum, Name, Version, Msg) Enum,
@@ -83,4 +83,9 @@ enum SanitizerHandler {
 #undef SANITIZER_CHECK
 };
 
+static_assert(BoundsSafety == 0x19,
+              "BoundsSafety must stay 0x19: it is encoded in -fbounds-safety "
+              "trap instructions (brk #0x5519, ud1l 0x19(%eax)) that debuggers 
"
+              "decode; append new checks at the end of LIST_SANITIZER_CHECKS");
+
 #endif // LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H
diff --git 
a/clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
 
b/clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
index def1f14baeafa..193a15349a8a6 100644
--- 
a/clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
+++ 
b/clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
@@ -84,7 +84,7 @@ char **__attribute__((alloc_align(2)))
 // CHECK-SANITIZE-TRAP-NEXT:    [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
 // CHECK-SANITIZE-TRAP-NEXT:    br i1 [[MASKCOND]], label [[CONT:%.*]], label 
[[TRAP:%.*]], !prof [[PROF1:![0-9]+]], !nosanitize [[META2:![0-9]+]]
 // CHECK-SANITIZE-TRAP:       trap:
-// CHECK-SANITIZE-TRAP-NEXT:    call void @llvm.ubsantrap(i8 25) 
#[[ATTR2:[0-9]+]], !nosanitize [[META2]]
+// CHECK-SANITIZE-TRAP-NEXT:    call void @llvm.ubsantrap(i8 26) 
#[[ATTR2:[0-9]+]], !nosanitize [[META2]]
 // CHECK-SANITIZE-TRAP-NEXT:    unreachable, !nosanitize [[META2]]
 // CHECK-SANITIZE-TRAP:       cont:
 // CHECK-SANITIZE-TRAP-NEXT:    ret ptr [[TMP0]]
diff --git 
a/clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
 
b/clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
index 8b214da33f685..04475be798d9f 100644
--- 
a/clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
+++ 
b/clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
@@ -84,7 +84,7 @@ char **__attribute__((alloc_align(2)))
 // CHECK-SANITIZE-TRAP-NEXT:    [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
 // CHECK-SANITIZE-TRAP-NEXT:    br i1 [[MASKCOND]], label [[CONT:%.*]], label 
[[TRAP:%.*]], !prof [[PROF1:![0-9]+]], !nosanitize [[META2:![0-9]+]]
 // CHECK-SANITIZE-TRAP:       trap:
-// CHECK-SANITIZE-TRAP-NEXT:    call void @llvm.ubsantrap(i8 25) 
#[[ATTR2:[0-9]+]], !nosanitize [[META2]]
+// CHECK-SANITIZE-TRAP-NEXT:    call void @llvm.ubsantrap(i8 26) 
#[[ATTR2:[0-9]+]], !nosanitize [[META2]]
 // CHECK-SANITIZE-TRAP-NEXT:    unreachable, !nosanitize [[META2]]
 // CHECK-SANITIZE-TRAP:       cont:
 // CHECK-SANITIZE-TRAP-NEXT:    ret ptr [[TMP0]]
diff --git 
a/clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp
 
b/clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp
index 396c4c78ab930..486ceb14ebffa 100644
--- 
a/clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp
+++ 
b/clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp
@@ -76,7 +76,7 @@ char **__attribute__((assume_aligned(0x100000000, 42)))
 // CHECK-SANITIZE-TRAP-NEXT:    [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
 // CHECK-SANITIZE-TRAP-NEXT:    br i1 [[MASKCOND]], label [[CONT:%.*]], label 
[[TRAP:%.*]], !prof [[PROF1:![0-9]+]], !nosanitize [[META2:![0-9]+]]
 // CHECK-SANITIZE-TRAP:       trap:
-// CHECK-SANITIZE-TRAP-NEXT:    call void @llvm.ubsantrap(i8 25) 
#[[ATTR3:[0-9]+]], !nosanitize [[META2]]
+// CHECK-SANITIZE-TRAP-NEXT:    call void @llvm.ubsantrap(i8 26) 
#[[ATTR3:[0-9]+]], !nosanitize [[META2]]
 // CHECK-SANITIZE-TRAP-NEXT:    unreachable, !nosanitize [[META2]]
 // CHECK-SANITIZE-TRAP:       cont:
 // CHECK-SANITIZE-TRAP-NEXT:    ret ptr [[TMP0]]
diff --git 
a/clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function.cpp
 
b/clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function.cpp
index 27a2447af7c9e..b8ffb8b3a2ca4 100644
--- 
a/clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function.cpp
+++ 
b/clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function.cpp
@@ -73,7 +73,7 @@ char **__attribute__((assume_aligned(128)))
 // CHECK-SANITIZE-TRAP-NEXT:    [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
 // CHECK-SANITIZE-TRAP-NEXT:    br i1 [[MASKCOND]], label [[CONT:%.*]], label 
[[TRAP:%.*]], !prof [[PROF1:![0-9]+]], !nosanitize [[META2:![0-9]+]]
 // CHECK-SANITIZE-TRAP:       trap:
-// CHECK-SANITIZE-TRAP-NEXT:    call void @llvm.ubsantrap(i8 25) 
#[[ATTR3:[0-9]+]], !nosanitize [[META2]]
+// CHECK-SANITIZE-TRAP-NEXT:    call void @llvm.ubsantrap(i8 26) 
#[[ATTR3:[0-9]+]], !nosanitize [[META2]]
 // CHECK-SANITIZE-TRAP-NEXT:    unreachable, !nosanitize [[META2]]
 // CHECK-SANITIZE-TRAP:       cont:
 // CHECK-SANITIZE-TRAP-NEXT:    ret ptr [[TMP0]]

``````````

</details>


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

Reply via email to