Skip to content

Commit 61779cf

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-resume-phi-using-PHI
2 parents 74eddb5 + b474c3f commit 61779cf

Some content is hidden

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

58 files changed

+1739
-1172
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ C Language Changes
226226
- Added the existing ``-Wduplicate-decl-specifier`` diagnostic, which is on by
227227
default, to ``-Wc++-compat`` because duplicated declaration specifiers are
228228
not valid in C++.
229+
- The ``[[clang::assume()]]`` attribute is now correctly recognized in C. The
230+
``__attribute__((assume()))`` form has always been supported, so the fix is
231+
specific to the attribute syntax used.
229232

230233
C2y Feature Support
231234
^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/SanitizerSpecialCaseList.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/Support/SpecialCaseList.h"
2121
#include <memory>
22+
#include <utility>
2223
#include <vector>
2324

2425
namespace llvm {
@@ -44,20 +45,24 @@ class SanitizerSpecialCaseList : public llvm::SpecialCaseList {
4445
StringRef Category = StringRef()) const;
4546

4647
// Query ignorelisted entries if any bit in Mask matches the entry's section.
47-
// Return 0 if not found. If found, return the line number (starts with 1).
48-
unsigned inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef Query,
49-
StringRef Category = StringRef()) const;
48+
// Return NotFound (0,0) if not found. If found, return the file index number
49+
// and the line number (FileIdx, LineNo) (FileIdx starts with 1 and LineNo
50+
// starts with 0).
51+
std::pair<unsigned, unsigned>
52+
inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef Query,
53+
StringRef Category = StringRef()) const;
5054

5155
protected:
5256
// Initialize SanitizerSections.
5357
void createSanitizerSections();
5458

5559
struct SanitizerSection {
56-
SanitizerSection(SanitizerMask SM, SectionEntries &E)
57-
: Mask(SM), Entries(E) {};
60+
SanitizerSection(SanitizerMask SM, SectionEntries &E, unsigned idx)
61+
: Mask(SM), Entries(E), FileIdx(idx) {};
5862

5963
SanitizerMask Mask;
6064
SectionEntries &Entries;
65+
unsigned FileIdx;
6166
};
6267

6368
std::vector<SanitizerSection> SanitizerSections;

clang/include/clang/Parse/Parser.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,11 +3037,11 @@ class Parser : public CodeCompletionHandler {
30373037

30383038
/// Parse the argument to C++23's [[assume()]] attribute. Returns true on
30393039
/// error.
3040-
bool ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs,
3041-
IdentifierInfo *AttrName,
3042-
SourceLocation AttrNameLoc,
3043-
SourceLocation *EndLoc,
3044-
ParsedAttr::Form Form);
3040+
bool
3041+
ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3042+
SourceLocation AttrNameLoc,
3043+
IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3044+
SourceLocation *EndLoc, ParsedAttr::Form Form);
30453045

30463046
/// Try to parse an 'identifier' which appears within an attribute-token.
30473047
///

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11170,6 +11170,8 @@ class Sema final : public SemaBase {
1117011170
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
1117111171
ArrayRef<Stmt *> Handlers);
1117211172

11173+
void DiagnoseExceptionUse(SourceLocation Loc, bool IsTry);
11174+
1117311175
StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
1117411176
SourceLocation TryLoc, Stmt *TryBlock,
1117511177
Stmt *Handler);

clang/lib/AST/ByteCode/DynamicAllocator.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ Block *DynamicAllocator::allocate(const Descriptor *D, unsigned EvalID,
8686
ID->IsInitialized = false;
8787
ID->IsVolatile = false;
8888

89-
ID->LifeState =
90-
AllocForm == Form::Operator ? Lifetime::Ended : Lifetime::Started;
91-
;
89+
if (D->isCompositeArray())
90+
ID->LifeState = Lifetime::Started;
91+
else
92+
ID->LifeState =
93+
AllocForm == Form::Operator ? Lifetime::Ended : Lifetime::Started;
9294

9395
B->IsDynamic = true;
9496

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,38 +1699,61 @@ bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
16991699
return Call(S, OpPC, F, VarArgSize);
17001700
}
17011701

1702+
static void startLifetimeRecurse(const Pointer &Ptr) {
1703+
if (const Record *R = Ptr.getRecord()) {
1704+
Ptr.startLifetime();
1705+
for (const Record::Field &Fi : R->fields())
1706+
startLifetimeRecurse(Ptr.atField(Fi.Offset));
1707+
return;
1708+
}
1709+
1710+
if (const Descriptor *FieldDesc = Ptr.getFieldDesc();
1711+
FieldDesc->isCompositeArray()) {
1712+
assert(Ptr.getLifetime() == Lifetime::Started);
1713+
for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I)
1714+
startLifetimeRecurse(Ptr.atIndex(I).narrow());
1715+
return;
1716+
}
1717+
1718+
Ptr.startLifetime();
1719+
}
1720+
17021721
bool StartLifetime(InterpState &S, CodePtr OpPC) {
17031722
const auto &Ptr = S.Stk.peek<Pointer>();
17041723
if (!CheckDummy(S, OpPC, Ptr, AK_Destroy))
17051724
return false;
1706-
1707-
Ptr.startLifetime();
1725+
startLifetimeRecurse(Ptr.narrow());
17081726
return true;
17091727
}
17101728

17111729
// FIXME: It might be better to the recursing as part of the generated code for
17121730
// a destructor?
17131731
static void endLifetimeRecurse(const Pointer &Ptr) {
1714-
Ptr.endLifetime();
17151732
if (const Record *R = Ptr.getRecord()) {
1733+
Ptr.endLifetime();
17161734
for (const Record::Field &Fi : R->fields())
17171735
endLifetimeRecurse(Ptr.atField(Fi.Offset));
17181736
return;
17191737
}
17201738

17211739
if (const Descriptor *FieldDesc = Ptr.getFieldDesc();
17221740
FieldDesc->isCompositeArray()) {
1741+
// No endLifetime() for array roots.
1742+
assert(Ptr.getLifetime() == Lifetime::Started);
17231743
for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I)
17241744
endLifetimeRecurse(Ptr.atIndex(I).narrow());
1745+
return;
17251746
}
1747+
1748+
Ptr.endLifetime();
17261749
}
17271750

17281751
/// Ends the lifetime of the peek'd pointer.
17291752
bool EndLifetime(InterpState &S, CodePtr OpPC) {
17301753
const auto &Ptr = S.Stk.peek<Pointer>();
17311754
if (!CheckDummy(S, OpPC, Ptr, AK_Destroy))
17321755
return false;
1733-
endLifetimeRecurse(Ptr);
1756+
endLifetimeRecurse(Ptr.narrow());
17341757
return true;
17351758
}
17361759

@@ -1739,7 +1762,7 @@ bool EndLifetimePop(InterpState &S, CodePtr OpPC) {
17391762
const auto &Ptr = S.Stk.pop<Pointer>();
17401763
if (!CheckDummy(S, OpPC, Ptr, AK_Destroy))
17411764
return false;
1742-
endLifetimeRecurse(Ptr);
1765+
endLifetimeRecurse(Ptr.narrow());
17431766
return true;
17441767
}
17451768

@@ -1758,9 +1781,9 @@ bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, const Expr *E,
17581781

17591782
// CheckLifetime for this and all base pointers.
17601783
for (Pointer P = Ptr;;) {
1761-
if (!CheckLifetime(S, OpPC, P, AK_Construct)) {
1784+
if (!CheckLifetime(S, OpPC, P, AK_Construct))
17621785
return false;
1763-
}
1786+
17641787
if (P.isRoot())
17651788
break;
17661789
P = P.getBase();

clang/lib/Basic/NoSanitizeList.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask,
4444

4545
bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
4646
StringRef Category) const {
47-
unsigned NoSanLine = SSCL->inSectionBlame(Mask, "src", FileName, Category);
48-
if (NoSanLine == 0)
47+
auto NoSan = SSCL->inSectionBlame(Mask, "src", FileName, Category);
48+
if (NoSan == llvm::SpecialCaseList::NotFound)
4949
return false;
50-
unsigned SanLine = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
51-
// If we have two cases such as `src:a.cpp=sanitize` and `src:a.cpp`, the
52-
// current entry override the previous entry.
53-
return !SanLine || NoSanLine > SanLine;
50+
auto San = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
51+
return San == llvm::SpecialCaseList::NotFound || NoSan > San;
5452
}
5553

5654
bool NoSanitizeList::containsMainFile(SanitizerMask Mask, StringRef FileName,

clang/lib/Basic/SanitizerSpecialCaseList.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,27 @@ void SanitizerSpecialCaseList::createSanitizerSections() {
5050
#undef SANITIZER
5151
#undef SANITIZER_GROUP
5252

53-
SanitizerSections.emplace_back(Mask, S.Entries);
53+
SanitizerSections.emplace_back(Mask, S.Entries, S.FileIdx);
5454
}
5555
}
5656

5757
bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix,
5858
StringRef Query,
5959
StringRef Category) const {
60-
return inSectionBlame(Mask, Prefix, Query, Category);
60+
return inSectionBlame(Mask, Prefix, Query, Category) != NotFound;
6161
}
6262

63-
unsigned SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask,
64-
StringRef Prefix,
65-
StringRef Query,
66-
StringRef Category) const {
63+
std::pair<unsigned, unsigned>
64+
SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask, StringRef Prefix,
65+
StringRef Query,
66+
StringRef Category) const {
6767
for (const auto &S : llvm::reverse(SanitizerSections)) {
6868
if (S.Mask & Mask) {
69-
unsigned lineNum =
69+
unsigned LineNum =
7070
SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category);
71-
if (lineNum > 0)
72-
return lineNum;
71+
if (LineNum > 0)
72+
return {S.FileIdx, LineNum};
7373
}
7474
}
75-
return 0;
75+
return NotFound;
7676
}

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5192,6 +5192,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51925192
}
51935193
}
51945194

5195+
// Optimization level for CodeGen.
5196+
if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
5197+
if (A->getOption().matches(options::OPT_O4)) {
5198+
CmdArgs.push_back("-O3");
5199+
D.Diag(diag::warn_O4_is_O3);
5200+
} else {
5201+
A->render(Args, CmdArgs);
5202+
}
5203+
}
5204+
51955205
// Unconditionally claim the printf option now to avoid unused diagnostic.
51965206
if (const Arg *PF = Args.getLastArg(options::OPT_mprintf_kind_EQ))
51975207
PF->claim();
@@ -5563,16 +5573,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
55635573
break;
55645574
}
55655575

5566-
// Optimization level for CodeGen.
5567-
if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
5568-
if (A->getOption().matches(options::OPT_O4)) {
5569-
CmdArgs.push_back("-O3");
5570-
D.Diag(diag::warn_O4_is_O3);
5571-
} else {
5572-
A->render(Args, CmdArgs);
5573-
}
5574-
}
5575-
55765576
// Input/Output file.
55775577
if (Output.getType() == types::TY_Dependencies) {
55785578
// Handled with other dependency code.
@@ -6453,16 +6453,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
64536453
// preprocessed inputs and configure concludes that -fPIC is not supported.
64546454
Args.ClaimAllArgs(options::OPT_D);
64556455

6456-
// Manually translate -O4 to -O3; let clang reject others.
6457-
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
6458-
if (A->getOption().matches(options::OPT_O4)) {
6459-
CmdArgs.push_back("-O3");
6460-
D.Diag(diag::warn_O4_is_O3);
6461-
} else {
6462-
A->render(Args, CmdArgs);
6463-
}
6464-
}
6465-
64666456
// Warn about ignored options to clang.
64676457
for (const Arg *A :
64686458
Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {

clang/lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ void Parser::ParseGNUAttributeArgs(
676676
Form);
677677
return;
678678
} else if (AttrKind == ParsedAttr::AT_CXXAssume) {
679-
ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, EndLoc, Form);
679+
ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, ScopeName,
680+
ScopeLoc, EndLoc, Form);
680681
return;
681682
}
682683

@@ -734,7 +735,8 @@ unsigned Parser::ParseClangAttributeArgs(
734735
break;
735736

736737
case ParsedAttr::AT_CXXAssume:
737-
ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, EndLoc, Form);
738+
ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, ScopeName,
739+
ScopeLoc, EndLoc, Form);
738740
break;
739741
}
740742
return !Attrs.empty() ? Attrs.begin()->getNumArgs() : 0;

0 commit comments

Comments
 (0)