Files
TheRock/compiler/amd-llvm/clang/test/AST/ByteCode/char-buffer-arithmetic.c
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

38 lines
1.8 KiB
C

// RUN: %clang_cc1 -std=c23 -triple x86_64 -verify -fsyntax-only -Wfortify-source -Wno-string-plus-int %s
// RUN: %clang_cc1 -std=c23 -triple x86_64 -verify -fsyntax-only -Wfortify-source -Wno-string-plus-int -fexperimental-new-constant-interpreter %s
void test(char *c) {
// We test offsets 0 to 4.
// 0: a no op of course
// 1,2: these result in a different length string than the buffer size
// 3: the last position: this hits ptr+object_size being a valid pointer,
// but not dereferencable
// 4: completely invalid pointer
__builtin_strcat(c, "42" + 0);
__builtin_strcat(c, "42" + 1);
__builtin_strcat(c, "42" + 2);
__builtin_strcat(c, "42" + 3);
__builtin_strcat(c, "42" + 4);
_Static_assert(__builtin_strlen("42" + 0) == 2);
// A test without a null terminator, this captures incorrect size computation
// and incorrectly specifying the buffer size to strlen.
char buffer[1];
static const char test_buffer[] = {'4','2'};
__builtin_strcpy(buffer, test_buffer + 0);
__builtin_strcpy(buffer, test_buffer + 1);
// Note: these show that we will not issue a fortify warning when the source
// buffer is not null terminated.
__builtin_strcpy(buffer, test_buffer + 2);
__builtin_strcpy(buffer, test_buffer + 3);
// Verifying strlen computes from the correct starting point.
_Static_assert(__builtin_strlen("42" + 1) == 1);
_Static_assert(__builtin_strlen("42" + 2) == 0);
_Static_assert(__builtin_strlen("42" + 3));
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
_Static_assert(__builtin_strlen("42" + 4));
// expected-error@-1 {{static assertion expression is not an integral constant expression}}
// expected-note@-2 {{cannot refer to element 4 of array of 3 elements in a constant expression}}
}