Skip to content

Commit ab63de8

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:881f20e958e80bd30463fc57d2d3e891bcb8a571 into amd-gfx:cbb3d19bf0f1
Local branch amd-gfx cbb3d19 Merged main:fe2ff54590c313551e7968179b48988ff0916290 into amd-gfx:57c0f5e83155 Remote branch main 881f20e Revert "[ctx_profile] Integration test (llvm#92456)"
2 parents cbb3d19 + 881f20e commit ab63de8

File tree

21 files changed

+579
-480
lines changed

21 files changed

+579
-480
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,10 @@ def FunctionMultiVersioning
14471447

14481448
def NoDeref : DiagGroup<"noderef">;
14491449

1450+
// -fbounds-safety and bounds annotation related warnings
1451+
def BoundsSafetyCountedByEltTyUnknownSize :
1452+
DiagGroup<"bounds-safety-counted-by-elt-type-unknown-size">;
1453+
14501454
// A group for cross translation unit static analysis related warnings.
14511455
def CrossTU : DiagGroup<"ctu">;
14521456

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6552,7 +6552,7 @@ def err_counted_by_attr_refer_to_union : Error<
65526552
def note_flexible_array_counted_by_attr_field : Note<
65536553
"field %0 declared here">;
65546554
def err_counted_by_attr_pointee_unknown_size : Error<
6555-
"'counted_by' cannot be applied to %select{"
6555+
"'counted_by' %select{cannot|should not}3 be applied to %select{"
65566556
"a pointer with pointee|" // pointer
65576557
"an array with element}0" // array
65586558
" of unknown size because %1 is %select{"
@@ -6561,8 +6561,14 @@ def err_counted_by_attr_pointee_unknown_size : Error<
65616561
"a function type|" // CountedByInvalidPointeeTypeKind::FUNCTION
65626562
// CountedByInvalidPointeeTypeKind::FLEXIBLE_ARRAY_MEMBER
65636563
"a struct type with a flexible array member"
6564+
"%select{|. This will be an error in a future compiler version}3"
6565+
""
65646566
"}2">;
65656567

6568+
def warn_counted_by_attr_elt_type_unknown_size :
6569+
Warning<err_counted_by_attr_pointee_unknown_size.Summary>,
6570+
InGroup<BoundsSafetyCountedByEltTyUnknownSize>;
6571+
65666572
let CategoryName = "ARC Semantic Issue" in {
65676573

65686574
// ARC-mode diagnostics.

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8687,20 +8687,33 @@ static bool CheckCountedByAttrOnField(
86878687
// Note: The `Decl::isFlexibleArrayMemberLike` check earlier on means
86888688
// only `PointeeTy->isStructureTypeWithFlexibleArrayMember()` is reachable
86898689
// when `FieldTy->isArrayType()`.
8690+
bool ShouldWarn = false;
86908691
if (PointeeTy->isIncompleteType()) {
86918692
InvalidTypeKind = CountedByInvalidPointeeTypeKind::INCOMPLETE;
86928693
} else if (PointeeTy->isSizelessType()) {
86938694
InvalidTypeKind = CountedByInvalidPointeeTypeKind::SIZELESS;
86948695
} else if (PointeeTy->isFunctionType()) {
86958696
InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION;
86968697
} else if (PointeeTy->isStructureTypeWithFlexibleArrayMember()) {
8698+
if (FieldTy->isArrayType()) {
8699+
// This is a workaround for the Linux kernel that has already adopted
8700+
// `counted_by` on a FAM where the pointee is a struct with a FAM. This
8701+
// should be an error because computing the bounds of the array cannot be
8702+
// done correctly without manually traversing every struct object in the
8703+
// array at runtime. To allow the code to be built this error is
8704+
// downgraded to a warning.
8705+
ShouldWarn = true;
8706+
}
86978707
InvalidTypeKind = CountedByInvalidPointeeTypeKind::FLEXIBLE_ARRAY_MEMBER;
86988708
}
86998709

87008710
if (InvalidTypeKind != CountedByInvalidPointeeTypeKind::VALID) {
8701-
S.Diag(FD->getBeginLoc(), diag::err_counted_by_attr_pointee_unknown_size)
8711+
unsigned DiagID = ShouldWarn
8712+
? diag::warn_counted_by_attr_elt_type_unknown_size
8713+
: diag::err_counted_by_attr_pointee_unknown_size;
8714+
S.Diag(FD->getBeginLoc(), DiagID)
87028715
<< SelectPtrOrArr << PointeeTy << (int)InvalidTypeKind
8703-
<< FD->getSourceRange();
8716+
<< (ShouldWarn ? 1 : 0) << FD->getSourceRange();
87048717
return true;
87058718
}
87068719

clang/test/Sema/attr-counted-by-vla.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,24 @@ struct has_annotated_VLA {
173173

174174
struct buffer_of_structs_with_unnannotated_vla {
175175
int count;
176-
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_unannotated_VLA' is a struct type with a flexible array member}}
176+
// Treating this as a warning is a temporary fix for existing attribute adopters. It **SHOULD BE AN ERROR**.
177+
// expected-warning@+1{{'counted_by' should not be applied to an array with element of unknown size because 'struct has_unannotated_VLA' is a struct type with a flexible array member. This will be an error in a future compiler version}}
177178
struct has_unannotated_VLA Arr[] __counted_by(count);
178179
};
179180

180181

181182
struct buffer_of_structs_with_annotated_vla {
182183
int count;
183-
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_annotated_VLA' is a struct type with a flexible array member}}
184+
// Treating this as a warning is a temporary fix for existing attribute adopters. It **SHOULD BE AN ERROR**.
185+
// expected-warning@+1{{'counted_by' should not be applied to an array with element of unknown size because 'struct has_annotated_VLA' is a struct type with a flexible array member. This will be an error in a future compiler version}}
184186
struct has_annotated_VLA Arr[] __counted_by(count);
185187
};
186188

187189
struct buffer_of_const_structs_with_annotated_vla {
188190
int count;
191+
// Treating this as a warning is a temporary fix for existing attribute adopters. It **SHOULD BE AN ERROR**.
189192
// Make sure the `const` qualifier is printed when printing the element type.
190-
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'const struct has_annotated_VLA' is a struct type with a flexible array member}}
193+
// expected-warning@+1{{'counted_by' should not be applied to an array with element of unknown size because 'const struct has_annotated_VLA' is a struct type with a flexible array member. This will be an error in a future compiler version}}
191194
const struct has_annotated_VLA Arr[] __counted_by(count);
192195
};
193196

compiler-rt/lib/ctx_profile/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,3 @@ append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS)
1818
if(COMPILER_RT_INCLUDE_TESTS)
1919
add_subdirectory(tests)
2020
endif()
21-
22-
add_compiler_rt_runtime(clang_rt.ctx_profile
23-
STATIC
24-
ARCHS ${CTX_PROFILE_SUPPORTED_ARCH}
25-
OBJECT_LIBS RTSanitizerCommon RTSanitizerCommonLibc
26-
CFLAGS ${EXTRA_FLAGS}
27-
SOURCES ${CTX_PROFILE_SOURCES}
28-
ADDITIONAL_HEADERS ${CTX_PROFILE_HEADERS}
29-
PARENT_TARGET ctx_profile)

compiler-rt/test/ctx_profile/TestCases/generate-context.cpp

Lines changed: 0 additions & 103 deletions
This file was deleted.

compiler-rt/test/ctx_profile/lit.cfg.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ def get_required_attr(config, attr_name):
2929
config.test_source_root = os.path.dirname(__file__)
3030
# Default test suffixes.
3131
config.suffixes = [".c", ".cpp", ".test"]
32-
33-
config.substitutions.append(
34-
("%clangxx ", " ".join([config.clang] + config.cxx_mode_flags) + " ")
35-
)

flang/include/flang/Semantics/tools.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ inline bool IsCUDADeviceContext(const Scope *scope) {
213213
}
214214

215215
inline bool HasCUDAAttr(const Symbol &sym) {
216-
if (const auto *details{
217-
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
216+
if (const auto *details{sym.GetUltimate().detailsIf<ObjectEntityDetails>()}) {
218217
if (details->cudaDataAttr()) {
219218
return true;
220219
}
@@ -224,17 +223,18 @@ inline bool HasCUDAAttr(const Symbol &sym) {
224223

225224
inline bool NeedCUDAAlloc(const Symbol &sym) {
226225
bool inDeviceSubprogram{IsCUDADeviceContext(&sym.owner())};
227-
if (Fortran::semantics::IsDummy(sym))
226+
if (IsDummy(sym)) {
228227
return false;
229-
if (const auto *details{
230-
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
228+
}
229+
if (const auto *details{sym.GetUltimate().detailsIf<ObjectEntityDetails>()}) {
231230
if (details->cudaDataAttr() &&
232231
(*details->cudaDataAttr() == common::CUDADataAttr::Device ||
233232
*details->cudaDataAttr() == common::CUDADataAttr::Managed ||
234233
*details->cudaDataAttr() == common::CUDADataAttr::Unified)) {
235234
// Descriptor is allocated on host when in host context.
236-
if (Fortran::semantics::IsAllocatable(sym))
235+
if (IsAllocatable(sym)) {
237236
return inDeviceSubprogram;
237+
}
238238
return true;
239239
}
240240
}
@@ -246,7 +246,7 @@ std::optional<common::CUDADataAttr> GetCUDADataAttr(const Symbol *);
246246

247247
// Return an error if a symbol is not accessible from a scope
248248
std::optional<parser::MessageFormattedText> CheckAccessibleSymbol(
249-
const semantics::Scope &, const Symbol &);
249+
const Scope &, const Symbol &);
250250

251251
// Analysis of image control statements
252252
bool IsImageControlStmt(const parser::ExecutableConstruct &);
@@ -706,14 +706,13 @@ inline const parser::Name *getDesignatorNameIfDataRef(
706706
bool CouldBeDataPointerValuedFunction(const Symbol *);
707707

708708
template <typename R, typename T>
709-
std::optional<R> GetConstExpr(
710-
Fortran::semantics::SemanticsContext &semanticsContext, const T &x) {
711-
using DefaultCharConstantType = Fortran::evaluate::Ascii;
712-
if (const auto *expr{Fortran::semantics::GetExpr(semanticsContext, x)}) {
713-
const auto foldExpr{Fortran::evaluate::Fold(
714-
semanticsContext.foldingContext(), Fortran::common::Clone(*expr))};
709+
std::optional<R> GetConstExpr(SemanticsContext &semanticsContext, const T &x) {
710+
using DefaultCharConstantType = evaluate::Ascii;
711+
if (const auto *expr{GetExpr(semanticsContext, x)}) {
712+
const auto foldExpr{evaluate::Fold(
713+
semanticsContext.foldingContext(), common::Clone(*expr))};
715714
if constexpr (std::is_same_v<R, std::string>) {
716-
return Fortran::evaluate::GetScalarConstantValue<DefaultCharConstantType>(
715+
return evaluate::GetScalarConstantValue<DefaultCharConstantType>(
717716
foldExpr);
718717
}
719718
}

0 commit comments

Comments
 (0)