Skip to content

Commit 1123da2

Browse files
authored
merge main into amd-staging (llvm#4218)
2 parents 3a3f484 + 2e1ad79 commit 1123da2

File tree

191 files changed

+9082
-3659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+9082
-3659
lines changed

bolt/test/X86/dwarf5-dwoid-no-dwoname.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Check that DWARF CU with a valid DWOId but missing a dwo_name is correctly detected.
22
# RUN: rm -rf %t && mkdir -p %t && cd %t
33
# RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %s -split-dwarf-file=main.dwo -o main.o
4-
# RUN: %clang -O3 -g -gdwarf-5 -gsplit-dwarf -Wl,-q %t/main.o -o main.exe
4+
# RUN: %clang %cflags -O3 -g -gdwarf-5 -gsplit-dwarf -Wl,-q %t/main.o -o main.exe
55
# RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -update-debug-sections 2>&1 | FileCheck %s --check-prefix=PRECHECK
66
# PRECHECK: BOLT-ERROR: broken DWARF found in CU at offset 0x3e (DWOId=0x0, missing DW_AT_dwo_name / DW_AT_GNU_dwo_name)
77

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ Attribute Changes in Clang
272272
attribute, allowing the attribute to only be attached to the declaration. Prior, this would be
273273
treated as an error where the definition and declaration would have differing types.
274274

275+
- New format attributes ``gnu_printf``, ``gnu_scanf``, ``gnu_strftime`` and ``gnu_strfmon`` are added
276+
as aliases for ``printf``, ``scanf``, ``strftime`` and ``strfmon``. (#GH16219)
277+
275278
Improvements to Clang's diagnostics
276279
-----------------------------------
277280

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ enum class FormatStringType {
503503
FreeBSDKPrintf,
504504
OSTrace,
505505
OSLog,
506-
Syslog,
507506
Unknown
508507
};
509508

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,52 @@ bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
237237
return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
238238
}
239239

240+
bool Context::evaluateString(State &Parent, const Expr *E,
241+
std::string &Result) {
242+
assert(Stk.empty());
243+
Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
244+
245+
auto PtrRes = C.interpretAsPointer(E, [&](const Pointer &Ptr) {
246+
const Descriptor *FieldDesc = Ptr.getFieldDesc();
247+
if (!FieldDesc->isPrimitiveArray())
248+
return false;
249+
250+
if (!Ptr.isConst())
251+
return false;
252+
253+
unsigned N = Ptr.getNumElems();
254+
255+
if (Ptr.elemSize() == 1 /* bytes */) {
256+
const char *Chars = reinterpret_cast<const char *>(Ptr.getRawAddress());
257+
unsigned Length = strnlen(Chars, N);
258+
// Wasn't null terminated.
259+
if (N == Length)
260+
return false;
261+
Result.assign(Chars, Length);
262+
return true;
263+
}
264+
265+
PrimType ElemT = FieldDesc->getPrimType();
266+
for (unsigned I = Ptr.getIndex(); I != N; ++I) {
267+
INT_TYPE_SWITCH(ElemT, {
268+
auto Elem = Ptr.elem<T>(I);
269+
if (Elem.isZero())
270+
return true;
271+
Result.push_back(static_cast<char>(Elem));
272+
});
273+
}
274+
// We didn't find a 0 byte.
275+
return false;
276+
});
277+
278+
if (PtrRes.isInvalid()) {
279+
C.cleanup();
280+
Stk.clear();
281+
return false;
282+
}
283+
return true;
284+
}
285+
240286
bool Context::evaluateStrlen(State &Parent, const Expr *E, uint64_t &Result) {
241287
assert(Stk.empty());
242288
Compiler<EvalEmitter> C(*this, *P, Parent, Stk);

clang/lib/AST/ByteCode/Context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class Context final {
6767
bool evaluateCharRange(State &Parent, const Expr *SizeExpr,
6868
const Expr *PtrExpr, std::string &Result);
6969

70+
/// Evaluate \param E and if it can be evaluated to a null-terminated string,
71+
/// copy the result into \param Result.
72+
bool evaluateString(State &Parent, const Expr *E, std::string &Result);
73+
7074
/// Evalute \param E and if it can be evaluated to a string literal,
7175
/// run strlen() on it.
7276
bool evaluateStrlen(State &Parent, const Expr *E, uint64_t &Result);

clang/lib/AST/ExprConstant.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18905,9 +18905,15 @@ std::optional<std::string> Expr::tryEvaluateString(ASTContext &Ctx) const {
1890518905
uint64_t Result;
1890618906
std::string StringResult;
1890718907

18908+
if (Info.EnableNewConstInterp) {
18909+
if (!Info.Ctx.getInterpContext().evaluateString(Info, this, StringResult))
18910+
return std::nullopt;
18911+
return StringResult;
18912+
}
18913+
1890818914
if (EvaluateBuiltinStrLen(this, Result, Info, &StringResult))
1890918915
return StringResult;
18910-
return {};
18916+
return std::nullopt;
1891118917
}
1891218918

1891318919
template <typename T>

clang/lib/Format/Format.cpp

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,47 +2185,68 @@ std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
21852185
if (Input.error())
21862186
return Input.error();
21872187

2188-
for (unsigned i = 0; i < Styles.size(); ++i) {
2189-
// Ensures that only the first configuration can skip the Language option.
2190-
if (Styles[i].Language == FormatStyle::LK_None && i != 0)
2188+
assert(!Styles.empty());
2189+
const auto StyleCount = Styles.size();
2190+
2191+
// Start from the second style as (only) the first one may be the default.
2192+
for (unsigned I = 1; I < StyleCount; ++I) {
2193+
const auto Lang = Styles[I].Language;
2194+
if (Lang == FormatStyle::LK_None)
21912195
return make_error_code(ParseError::Error);
21922196
// Ensure that each language is configured at most once.
2193-
for (unsigned j = 0; j < i; ++j) {
2194-
if (Styles[i].Language == Styles[j].Language) {
2197+
for (unsigned J = 0; J < I; ++J) {
2198+
if (Lang == Styles[J].Language) {
21952199
LLVM_DEBUG(llvm::dbgs()
21962200
<< "Duplicate languages in the config file on positions "
2197-
<< j << " and " << i << "\n");
2201+
<< J << " and " << I << '\n');
21982202
return make_error_code(ParseError::Error);
21992203
}
22002204
}
22012205
}
2202-
// Look for a suitable configuration starting from the end, so we can
2203-
// find the configuration for the specific language first, and the default
2204-
// configuration (which can only be at slot 0) after it.
2205-
FormatStyle::FormatStyleSet StyleSet;
2206-
bool LanguageFound = false;
2207-
for (const FormatStyle &Style : llvm::reverse(Styles)) {
2208-
const auto Lang = Style.Language;
2209-
if (Lang != FormatStyle::LK_None)
2210-
StyleSet.Add(Style);
2211-
if (Lang == Language ||
2212-
// For backward compatibility.
2213-
(Lang == FormatStyle::LK_Cpp && Language == FormatStyle::LK_C)) {
2214-
LanguageFound = true;
2215-
} else if (IsDotHFile && Language == FormatStyle::LK_Cpp &&
2216-
(Lang == FormatStyle::LK_C || Lang == FormatStyle::LK_ObjC)) {
2217-
Language = Lang;
2218-
LanguageFound = true;
2206+
2207+
int LanguagePos = -1; // Position of the style for Language.
2208+
int CppPos = -1; // Position of the style for C++.
2209+
int CPos = -1; // Position of the style for C.
2210+
2211+
// Search Styles for Language and store the positions of C++ and C styles in
2212+
// case Language is not found.
2213+
for (unsigned I = 0; I < StyleCount; ++I) {
2214+
const auto Lang = Styles[I].Language;
2215+
if (Lang == Language) {
2216+
LanguagePos = I;
2217+
break;
22192218
}
2220-
}
2221-
if (!LanguageFound) {
2222-
if (Styles.empty() || Styles[0].Language != FormatStyle::LK_None)
2219+
if (Lang == FormatStyle::LK_Cpp)
2220+
CppPos = I;
2221+
else if (Lang == FormatStyle::LK_C)
2222+
CPos = I;
2223+
}
2224+
2225+
// If Language is not found, use the default style if there is one. Otherwise,
2226+
// use the C style for C++ .h files and for backward compatibility, the C++
2227+
// style for .c files.
2228+
if (LanguagePos < 0) {
2229+
if (Styles[0].Language == FormatStyle::LK_None) // Default style.
2230+
LanguagePos = 0;
2231+
else if (IsDotHFile && Language == FormatStyle::LK_Cpp)
2232+
LanguagePos = CPos;
2233+
else if (!IsDotHFile && Language == FormatStyle::LK_C)
2234+
LanguagePos = CppPos;
2235+
if (LanguagePos < 0)
22232236
return make_error_code(ParseError::Unsuitable);
2224-
FormatStyle DefaultStyle = Styles[0];
2225-
DefaultStyle.Language = Language;
2226-
StyleSet.Add(std::move(DefaultStyle));
22272237
}
2228-
*Style = *StyleSet.Get(Language);
2238+
2239+
for (const auto &S : llvm::reverse(llvm::drop_begin(Styles)))
2240+
Style->StyleSet.Add(S);
2241+
2242+
*Style = Styles[LanguagePos];
2243+
2244+
if (LanguagePos == 0) {
2245+
if (Style->Language == FormatStyle::LK_None) // Default style.
2246+
Style->Language = Language;
2247+
Style->StyleSet.Add(*Style);
2248+
}
2249+
22292250
if (Style->InsertTrailingCommas != FormatStyle::TCS_None &&
22302251
Style->BinPackArguments) {
22312252
// See comment on FormatStyle::TSC_Wrapped.
@@ -2256,14 +2277,8 @@ FormatStyle::FormatStyleSet::Get(FormatStyle::LanguageKind Language) const {
22562277
if (!Styles)
22572278
return std::nullopt;
22582279
auto It = Styles->find(Language);
2259-
if (It == Styles->end()) {
2260-
if (Language != FormatStyle::LK_C)
2261-
return std::nullopt;
2262-
// For backward compatibility.
2263-
It = Styles->find(FormatStyle::LK_Cpp);
2264-
if (It == Styles->end())
2265-
return std::nullopt;
2266-
}
2280+
if (It == Styles->end())
2281+
return std::nullopt;
22672282
FormatStyle Style = It->second;
22682283
Style.StyleSet = *this;
22692284
return Style;

clang/lib/Sema/SemaAMDGPU.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID,
5959
[[fallthrough]];
6060
}
6161
default:
62-
Diag(ArgExpr->getExprLoc(), diag::err_amdgcn_load_lds_size_invalid_value)
62+
SemaRef.targetDiag(ArgExpr->getExprLoc(),
63+
diag::err_amdgcn_load_lds_size_invalid_value)
6364
<< ArgExpr->getSourceRange();
64-
Diag(ArgExpr->getExprLoc(), diag::note_amdgcn_load_lds_size_valid_value)
65+
SemaRef.targetDiag(ArgExpr->getExprLoc(),
66+
diag::note_amdgcn_load_lds_size_valid_value)
6567
<< HasGFX950Insts << ArgExpr->getSourceRange();
6668
return true;
6769
}

clang/lib/Sema/SemaChecking.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6866,11 +6866,12 @@ StringRef Sema::GetFormatStringTypeName(FormatStringType FST) {
68666866

68676867
FormatStringType Sema::GetFormatStringType(StringRef Flavor) {
68686868
return llvm::StringSwitch<FormatStringType>(Flavor)
6869-
.Case("scanf", FormatStringType::Scanf)
6870-
.Cases("printf", "printf0", "syslog", FormatStringType::Printf)
6869+
.Cases("gnu_scanf", "scanf", FormatStringType::Scanf)
6870+
.Cases("gnu_printf", "printf", "printf0", "syslog",
6871+
FormatStringType::Printf)
68716872
.Cases("NSString", "CFString", FormatStringType::NSString)
6872-
.Case("strftime", FormatStringType::Strftime)
6873-
.Case("strfmon", FormatStringType::Strfmon)
6873+
.Cases("gnu_strftime", "strftime", FormatStringType::Strftime)
6874+
.Cases("gnu_strfmon", "strfmon", FormatStringType::Strfmon)
68746875
.Cases("kprintf", "cmn_err", "vcmn_err", "zcmn_err",
68756876
FormatStringType::Kprintf)
68766877
.Case("freebsd_kprintf", FormatStringType::FreeBSDKPrintf)
@@ -6990,7 +6991,6 @@ bool Sema::CheckFormatArguments(ArrayRef<const Expr *> Args,
69906991
case FormatStringType::Kprintf:
69916992
case FormatStringType::FreeBSDKPrintf:
69926993
case FormatStringType::Printf:
6993-
case FormatStringType::Syslog:
69946994
Diag(FormatLoc, diag::note_format_security_fixit)
69956995
<< FixItHint::CreateInsertion(FormatLoc, "\"%s\", ");
69966996
break;
@@ -9120,8 +9120,7 @@ static void CheckFormatString(
91209120
if (Type == FormatStringType::Printf || Type == FormatStringType::NSString ||
91219121
Type == FormatStringType::Kprintf ||
91229122
Type == FormatStringType::FreeBSDKPrintf ||
9123-
Type == FormatStringType::OSLog || Type == FormatStringType::OSTrace ||
9124-
Type == FormatStringType::Syslog) {
9123+
Type == FormatStringType::OSLog || Type == FormatStringType::OSTrace) {
91259124
bool IsObjC =
91269125
Type == FormatStringType::NSString || Type == FormatStringType::OSTrace;
91279126
if (ReferenceFormatString == nullptr) {
@@ -9157,8 +9156,7 @@ bool Sema::CheckFormatStringsCompatible(
91579156
if (Type != FormatStringType::Printf && Type != FormatStringType::NSString &&
91589157
Type != FormatStringType::Kprintf &&
91599158
Type != FormatStringType::FreeBSDKPrintf &&
9160-
Type != FormatStringType::OSLog && Type != FormatStringType::OSTrace &&
9161-
Type != FormatStringType::Syslog)
9159+
Type != FormatStringType::OSLog && Type != FormatStringType::OSTrace)
91629160
return true;
91639161

91649162
bool IsObjC =
@@ -9192,8 +9190,7 @@ bool Sema::ValidateFormatString(FormatStringType Type,
91929190
if (Type != FormatStringType::Printf && Type != FormatStringType::NSString &&
91939191
Type != FormatStringType::Kprintf &&
91949192
Type != FormatStringType::FreeBSDKPrintf &&
9195-
Type != FormatStringType::OSLog && Type != FormatStringType::OSTrace &&
9196-
Type != FormatStringType::Syslog)
9193+
Type != FormatStringType::OSLog && Type != FormatStringType::OSTrace)
91979194
return true;
91989195

91999196
FormatStringLiteral RefLit = Str;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,10 +3629,11 @@ static FormatAttrKind getFormatAttrKind(StringRef Format) {
36293629
// Check for formats that get handled specially.
36303630
.Case("NSString", NSStringFormat)
36313631
.Case("CFString", CFStringFormat)
3632-
.Case("strftime", StrftimeFormat)
3632+
.Cases("gnu_strftime", "strftime", StrftimeFormat)
36333633

36343634
// Otherwise, check for supported formats.
3635-
.Cases("scanf", "printf", "printf0", "strfmon", SupportedFormat)
3635+
.Cases("gnu_scanf", "scanf", "gnu_printf", "printf", "printf0",
3636+
"gnu_strfmon", "strfmon", SupportedFormat)
36363637
.Cases("cmn_err", "vcmn_err", "zcmn_err", SupportedFormat)
36373638
.Cases("kprintf", "syslog", SupportedFormat) // OpenBSD.
36383639
.Case("freebsd_kprintf", SupportedFormat) // FreeBSD.

0 commit comments

Comments
 (0)