Skip to content

[BoundsSafety][NFC] Fix remaining bounds safety test failures in next #9862

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

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7746,7 +7746,7 @@ bool checkDynamicCountSizeForAssignmentWithKnownCount(

const bool IsImplicitInitExpr = isa<ImplicitValueInitExpr>(RHSExpr);
const bool IsNull =
IsImplicitInitExpr || RHSExpr->isNullPointerConstant(
IsImplicitInitExpr || RHSExpr->isNullPointerConstantIgnoreCastsAndOVEs(
S.Context, Expr::NPC_ValueDependentIsNotNull);
const bool IsNonnull = CAT; // Array decays to nonnull pointer.

Expand Down
2 changes: 1 addition & 1 deletion clang/test/BoundsSafety/AST/redundant-attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ my_c_ptr_nullable_bidi_t __bidi_indexable def_c_nullable_bidi_ptr;
// CHECK-NEXT: PointerType {{.*}} 'const int *__bidi_indexable'
// CHECK-NEXT: QualType {{.*}} 'const int' const
// CHECK-NEXT: BuiltinType {{.*}} 'int'
// CHECK-NEXT: VarDecl {{.*}} def_c_nullable_bidi_ptr 'my_c_ptr_nullable_bidi_t':'const int *__bidi_indexable'
// CHECK-NEXT: VarDecl {{.*}} def_c_nullable_bidi_ptr 'const int *__bidi_indexable _Nullable':'const int *__bidi_indexable'
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void f_outlen(char *__counted_by(*outLen) derOut, unsigned long long *outLen) {
// UBSAN-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[TMP_SROA_0_0_COPYLOAD]] to i64, {{!nosanitize ![0-9]+}}
// UBSAN-NEXT: [[TMP1:%.*]] = add i64 [[OFFSET]], [[TMP0]], {{!nosanitize ![0-9]+}}
// UBSAN-NEXT: [[TMP2:%.*]] = icmp ne ptr [[TMP_SROA_0_0_COPYLOAD]], null, {{!nosanitize ![0-9]+}}
// UBSAN-NEXT: [[TMP3:%.*]] = icmp ne i64 [[TMP1]], 0, {{!nosanitize ![0-9]+}}
// UBSAN-NEXT: [[TMP4:%.*]] = and i1 [[TMP2]], [[TMP3]], {{!nosanitize ![0-9]+}}
// UBSAN-NEXT: [[TMP3:%.*]] = icmp eq i64 [[TMP1]], 0
// UBSAN-NEXT: [[TMP4:%.*]] = xor i1 [[TMP2]], [[TMP3]]
// UBSAN-NEXT: [[TMP5:%.*]] = icmp uge i64 [[TMP1]], [[TMP0]], {{!nosanitize ![0-9]+}}
// UBSAN-NEXT: [[TMP6:%.*]] = and i1 [[TMP5]], [[TMP4]], {{!nosanitize ![0-9]+}}
// UBSAN-NEXT: br i1 [[TMP6]], label [[CONT:%.*]], label [[TRAP:%.*]], {{!nosanitize ![0-9]+}}
Expand Down
6 changes: 3 additions & 3 deletions clang/test/BoundsSafety/PCH/count-increment-with-pch.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py

// Test without pch.
// RUN: %clang_cc1 -fbounds-safety -include %s -fsyntax-only -verify %s
// RUN: %clang_cc1 -fbounds-safety -include %s -triple arm64-apple-ios -fsyntax-only -verify %s

// Test with pch.
// RUN: %clang_cc1 -fbounds-safety -emit-pch -o %t %s
// RUN: %clang_cc1 -fbounds-safety -include-pch %t -verify -emit-llvm -O0 %s -o - | FileCheck %s
// RUN: %clang_cc1 -fbounds-safety -triple arm64-apple-ios -emit-pch -o %t %s
// RUN: %clang_cc1 -fbounds-safety -triple arm64-apple-ios -include-pch %t -verify -emit-llvm -O0 %s -o - | FileCheck %s
// expected-no-diagnostics
#include <ptrcheck.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma clang system_header

const char *mock_system_func(void);
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

// RUN: %clang_cc1 -fsyntax-only -fbounds-safety -verify %s
// RUN: %clang_cc1 -fsyntax-only -fbounds-safety -clang-vendor-feature=+disableOVEimplicitConv -verify %s

// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fsyntax-only -clang-vendor-feature=+disableOVEimplicitConv -verify %s

#include <stdint.h>
#include <ptrcheck.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef typeof(*bar) * my_manual_ptr_t;
void typedefs_of_typeof() {
// expected-error@+1{{initializing 'my_t *__single' (aka 'char *__single') with an expression of incompatible type 'char * _Nullable' casts away '__unsafe_indexable' qualifier; use '__unsafe_forge_single' or '__unsafe_forge_bidi_indexable' to perform this conversion}}
my_t * __single p1 = bar;
// expected-error@+1{{initializing 'my_ptr_t __single' (aka 'char *__single') with an expression of incompatible type 'char * _Nullable' casts away '__unsafe_indexable' qualifier; use '__unsafe_forge_single' or '__unsafe_forge_bidi_indexable' to perform this conversion}}
// expected-error@+1{{initializing 'char *__single _Nullable' with an expression of incompatible type 'char * _Nullable' casts away '__unsafe_indexable' qualifier; use '__unsafe_forge_single' or '__unsafe_forge_bidi_indexable' to perform this conversion}}
my_ptr_t __single p2 = bar;
// expected-error@+1{{initializing 'my_manual_ptr_t __single' (aka 'char *__single') with an expression of incompatible type 'char * _Nullable' casts away '__unsafe_indexable' qualifier; use '__unsafe_forge_single' or '__unsafe_forge_bidi_indexable' to perform this conversion}}
my_manual_ptr_t __single p3 = bar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#define UNLOCK_FUNCTION(...) __attribute__ ((unlock_function(__VA_ARGS__)))

void elf_fun_params(int lvar EXCLUSIVE_LOCK_FUNCTION()); // \
// expected-warning {{'exclusive_lock_function' attribute only applies to functions}}
// expected-warning {{'exclusive_lock_function' attribute applies to function parameters only if their type is a reference to a 'scoped_lockable'-annotated type}}
void slf_fun_params(int lvar SHARED_LOCK_FUNCTION()); // \
// expected-warning {{'shared_lock_function' attribute only applies to functions}}
// expected-warning {{'shared_lock_function' attribute applies to function parameters only if their type is a reference to a 'scoped_lockable'-annotated type}}
void uf_fun_params(int lvar UNLOCK_FUNCTION()); // \
// expected-warning {{'unlock_function' attribute only applies to functions}}
// expected-warning {{'unlock_function' attribute applies to function parameters only if their type is a reference to a 'scoped_lockable'-annotated type}}

// regression tests added for rdar://92699615
typedef bool __attribute__((capability("role"))) role_t;
Expand Down
11 changes: 6 additions & 5 deletions clang/test/BoundsSafety/Sema/static-bound-ptr-init.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

// RUN: %clang_cc1 -fsyntax-only -fbounds-safety -verify %s
// RUN: %clang_cc1 -fsyntax-only -fbounds-safety -x objective-c -fbounds-attributes-objc-experimental -verify %s
// RUN: %clang_cc1 -fsyntax-only -fbounds-safety -I%S/SystemHeaders/include -verify %s
// RUN: %clang_cc1 -fsyntax-only -fbounds-safety -I%S/SystemHeaders/include -x objective-c -fbounds-attributes-objc-experimental -verify %s

#include <ptrcheck.h>
#include <static-bound-ptr-init.h>
struct T {
void (*fp)(const struct T *t);
int i;
Expand Down Expand Up @@ -57,10 +58,10 @@ void *__single s_p3 = foo;
// T -> U: P
void *__unsafe_indexable ui_p2 = foo;

// Special case: "unspecified" should convert to __unsafe_indexable
const char *__unsafe_indexable ui_p3 = __builtin_xnu_type_signature(struct T);

void Test () {
// Special case: "unspecified" should convert to __unsafe_indexable
const char *__unsafe_indexable ui_p3 = mock_system_func();

static int len1;
// B -> C: R
// expected-warning@+1{{possibly initializing 'c_p1' of type 'int *__single __counted_by(len1)' (aka 'int *__single') and implicit count value of 0 with non-null, which creates a non-dereferenceable pointer; explicitly set count value to 0 to remove this warning}}
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Sema/builtin-counted-by-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ void test2(struct fam_struct *ptr, int idx) {
void test3(struct fam_struct *ptr, int idx) {
__builtin_counted_by_ref(&ptr->array[0]); // expected-error {{'__builtin_counted_by_ref' argument must reference a flexible array member}}
__builtin_counted_by_ref(&ptr->array[idx]); // expected-error {{'__builtin_counted_by_ref' argument must reference a flexible array member}}
// XXX: These are extra diagnostics that -fbounds-safety emits, which the upstream doesn't have yet.
// expected-note@+2{{remove '&' to get address as 'int *' instead of 'int (*)[] __counted_by(count)' (aka 'int (*)[]')}}
// expected-error@+1{{cannot take address of incomplete __counted_by array}}
__builtin_counted_by_ref(&ptr->array); // expected-error {{'__builtin_counted_by_ref' argument must reference a flexible array member}}
__builtin_counted_by_ref(ptr->x); // expected-error {{'__builtin_counted_by_ref' argument must reference a flexible array member}}
__builtin_counted_by_ref(&ptr->x); // expected-error {{'__builtin_counted_by_ref' argument must reference a flexible array member}}
Expand Down