Skip to content

[BoundsSafety] __single pointers are not null-checked. #10944

@zyedidia

Description

@zyedidia

In the description of the -fbounds-safety feature, it says "Dereferencing a __single pointer is allowed but it requires a null check."

However, in my testing of the feature preview (implemented here: https://github.com/swiftlang/llvm-project/tree/stable/20240723) it seems like there is no null check performed. I tried compiling the following program:

#include <ptrcheck.h>

int foo(int *__single p) {
  return *p;
}

int bar(int *__counted_by_or_null(1) p) {
  return *p;
}
$ clang -fbounds-safety -S test.c -O2 -target aarch64

This gives the following assembly (abbreviated):

foo:
	ldr	w0, [x0]
	ret

bar:
	cbz	x0, .LBB1_3
	add	x8, x0, #4
	cmp	x8, x0
	b.lo	.LBB1_3
	ldr	w0, [x0]
	ret
.LBB1_3:
	brk	#0x5519

bar contains a check, but foo has no check and directly dereferences the __single input pointer. Please let me know if I am using the wrong version or doing something incorrect. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:bounds-safetyIssue relating to the experimental -fbounds-safety feature in Clang

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions