Summary:
When using -ftrivial-auto-var-init=* options to initiate automatic
variables in a file, to disable initialization on some variables,
currently we have to manually annotate the variables with uninitialized
attribute, such as
int dont_initialize_me __attribute((uninitialized));
Making pragma clang attribute to support this attribute would make
annotating variables much easier, and could be particular useful for
bisection efforts, e.g.
void use(void*);
void buggy() {
int arr[256];
int boom;
float bam;
struct { int oops; } oops;
union { int oof; float aaaaa; } oof;
use(&arr);
use(&boom);
use(&bam);
use(&oops);
use(&oof);
}
Reviewers: jfb, rjmccall, aaron.ballman
Reviewed By: jfb, aaron.ballman
Subscribers: aaron.ballman, george.burgess.iv, dexonsmith, MaskRay, phosek, hubert.reinterpretcast, gbiv, manojgupta, llozano, srhines, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D78693
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks %s -emit-llvm -o - | FileCheck %s -check-prefix=UNINIT
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s -check-prefix=PATTERN
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s -check-prefix=ZERO
|
|
|
|
template<typename T> void used(T &) noexcept;
|
|
|
|
extern "C" {
|
|
|
|
// UNINIT-LABEL: test_attribute_uninitialized(
|
|
// UNINIT: alloca
|
|
// UNINIT-NEXT: call void
|
|
// ZERO-LABEL: test_attribute_uninitialized(
|
|
// ZERO: alloca
|
|
// ZERO-NEXT: call void
|
|
// PATTERN-LABEL: test_attribute_uninitialized(
|
|
// PATTERN: alloca
|
|
// PATTERN-NEXT: call void
|
|
void test_attribute_uninitialized() {
|
|
[[clang::uninitialized]] int i;
|
|
used(i);
|
|
}
|
|
|
|
#pragma clang attribute push([[clang::uninitialized]], apply_to = variable(is_local))
|
|
// UNINIT-LABEL: test_pragma_attribute_uninitialized(
|
|
// UNINIT: alloca
|
|
// UNINIT-NEXT: call void
|
|
// ZERO-LABEL: test_pragma_attribute_uninitialized(
|
|
// ZERO: alloca
|
|
// ZERO-NEXT: call void
|
|
// PATTERN-LABEL: test_pragma_attribute_uninitialized(
|
|
// PATTERN: alloca
|
|
// PATTERN-NEXT: call void
|
|
void test_pragma_attribute_uninitialized() {
|
|
int i;
|
|
used(i);
|
|
}
|
|
#pragma clang attribute pop
|
|
|
|
} // extern "C"
|