Files
TheRock/compiler/amd-llvm/clang/test/SemaCXX/warn-unsafe-buffer-usage-template-instantiation-notes.cpp
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

48 lines
2.1 KiB
C++

// Without -fsafe-buffer-usage-suggestions, -Wunsafe-buffer-usage analysis
// runs per-Decl during parsing, so the template instantiation stack is
// available and instantiation notes are emitted (rdar://107480207).
//
// With -fsafe-buffer-usage-suggestions, the analysis runs at end-of-TU
// where the instantiation stack is no longer available, so instantiation
// notes are not yet emitted.
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -verify %s
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
// RUN: -verify=with-fixit %s
void use(int);
template<typename T>
void templateFunction(T *p) { // with-fixit-warning{{'p' is an unsafe pointer used for buffer access}}
use(p[5]); // expected-warning{{unsafe buffer access}} \
expected-note{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}} \
with-fixit-note{{used in buffer access here}}
}
void instantiate(int *p) {
templateFunction(p); // expected-note{{in instantiation of function template specialization 'templateFunction<int>' requested here}}
}
template<typename T>
T templateReturn(T *p) { // with-fixit-warning{{'p' is an unsafe pointer used for buffer access}}
return p[5]; // expected-warning{{unsafe buffer access}} \
expected-note{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}} \
with-fixit-note{{used in buffer access here}}
}
void instantiate2(int *p) {
templateReturn(p); // expected-note{{in instantiation of function template specialization 'templateReturn<int>' requested here}}
}
template<typename T>
void templateArithmetic(T *p) { // with-fixit-warning{{'p' is an unsafe pointer used for buffer access}}
use(*(p + 3)); // expected-warning{{unsafe pointer arithmetic}} \
expected-note{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}} \
with-fixit-note{{used in pointer arithmetic here}}
}
void instantiate3(int *p) {
templateArithmetic(p); // expected-note{{in instantiation of function template specialization 'templateArithmetic<int>' requested here}}
}