Skip to content

Commit 2ab2251

Browse files
committed
Merge "merge main into amd-stg-open" into amd-stg-open
2 parents ad3faae + d94f216 commit 2ab2251

File tree

106 files changed

+6887
-2407
lines changed

Some content is hidden

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

106 files changed

+6887
-2407
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,45 +118,50 @@ static void updateAssignmentLevel(
118118
}
119119
}
120120

121-
static std::pair<const FieldDecl *, const Expr *>
121+
struct AssignmentPair {
122+
const FieldDecl *Field;
123+
const Expr *Init;
124+
};
125+
126+
static std::optional<AssignmentPair>
122127
isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,
123128
const CXXConstructorDecl *Ctor) {
124129
if (const auto *BO = dyn_cast<BinaryOperator>(S)) {
125130
if (BO->getOpcode() != BO_Assign)
126-
return std::make_pair(nullptr, nullptr);
131+
return {};
127132

128133
const auto *ME = dyn_cast<MemberExpr>(BO->getLHS()->IgnoreParenImpCasts());
129134
if (!ME)
130-
return std::make_pair(nullptr, nullptr);
135+
return {};
131136

132137
const auto *Field = dyn_cast<FieldDecl>(ME->getMemberDecl());
133138
if (!Field)
134-
return std::make_pair(nullptr, nullptr);
139+
return {};
135140

136141
if (!isa<CXXThisExpr>(ME->getBase()))
137-
return std::make_pair(nullptr, nullptr);
142+
return {};
138143
const Expr *Init = BO->getRHS()->IgnoreParenImpCasts();
139-
return std::make_pair(Field, Init);
144+
return AssignmentPair{Field, Init};
140145
}
141146
if (const auto *COCE = dyn_cast<CXXOperatorCallExpr>(S)) {
142147
if (COCE->getOperator() != OO_Equal)
143-
return std::make_pair(nullptr, nullptr);
148+
return {};
144149

145150
const auto *ME =
146151
dyn_cast<MemberExpr>(COCE->getArg(0)->IgnoreParenImpCasts());
147152
if (!ME)
148-
return std::make_pair(nullptr, nullptr);
153+
return {};
149154

150155
const auto *Field = dyn_cast<FieldDecl>(ME->getMemberDecl());
151156
if (!Field)
152-
return std::make_pair(nullptr, nullptr);
157+
return {};
153158

154159
if (!isa<CXXThisExpr>(ME->getBase()))
155-
return std::make_pair(nullptr, nullptr);
160+
return {};
156161
const Expr *Init = COCE->getArg(1)->IgnoreParenImpCasts();
157-
return std::make_pair(Field, Init);
162+
return AssignmentPair{Field, Init};
158163
}
159-
return std::make_pair(nullptr, nullptr);
164+
return {};
160165
}
161166

162167
PreferMemberInitializerCheck::PreferMemberInitializerCheck(
@@ -216,11 +221,12 @@ void PreferMemberInitializerCheck::check(
216221
return;
217222
}
218223

219-
const FieldDecl *Field = nullptr;
220-
const Expr *InitValue = nullptr;
221-
std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor);
222-
if (!Field)
224+
std::optional<AssignmentPair> AssignmentToMember =
225+
isAssignmentToMemberOf(Class, S, Ctor);
226+
if (!AssignmentToMember)
223227
continue;
228+
const FieldDecl *Field = AssignmentToMember->Field;
229+
const Expr *InitValue = AssignmentToMember->Init;
224230
updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
225231
if (!canAdvanceAssignment(AssignedFields[Field]))
226232
continue;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===--- APINotesOptions.h --------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
10+
#define LLVM_CLANG_APINOTES_APINOTESOPTIONS_H
11+
12+
#include "llvm/Support/VersionTuple.h"
13+
#include <string>
14+
#include <vector>
15+
16+
namespace clang {
17+
18+
/// Tracks various options which control how API notes are found and handled.
19+
class APINotesOptions {
20+
public:
21+
/// The Swift version which should be used for API notes.
22+
llvm::VersionTuple SwiftVersion;
23+
24+
/// The set of search paths where we API notes can be found for particular
25+
/// modules.
26+
///
27+
/// The API notes in this directory are stored as <ModuleName>.apinotes, and
28+
/// are only applied when building the module <ModuleName>.
29+
std::vector<std::string> ModuleSearchPaths;
30+
};
31+
32+
} // namespace clang
33+
34+
#endif // LLVM_CLANG_APINOTES_APINOTESOPTIONS_H

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,14 +998,24 @@ def warn_npot_ms_struct : Warning<
998998
"data types with sizes that aren't a power of two">,
999999
DefaultError, InGroup<IncompatibleMSStruct>;
10001000

1001+
// -Wpadded-bitfield
1002+
def warn_padded_struct_bitfield : Warning<
1003+
"padding %select{struct|interface|class}0 %1 with %2 "
1004+
"%select{byte|bit}3%s2 to align %4">,
1005+
InGroup<PaddedBitField>, DefaultIgnore;
1006+
def warn_padded_struct_anon_bitfield : Warning<
1007+
"padding %select{struct|interface|class}0 %1 with %2 "
1008+
"%select{byte|bit}3%s2 to align anonymous bit-field">,
1009+
InGroup<PaddedBitField>, DefaultIgnore;
1010+
10011011
// -Wpadded, -Wpacked
10021012
def warn_padded_struct_field : Warning<
10031013
"padding %select{struct|interface|class}0 %1 with %2 "
10041014
"%select{byte|bit}3%s2 to align %4">,
10051015
InGroup<Padded>, DefaultIgnore;
10061016
def warn_padded_struct_anon_field : Warning<
10071017
"padding %select{struct|interface|class}0 %1 with %2 "
1008-
"%select{byte|bit}3%s2 to align anonymous bit-field">,
1018+
"%select{byte|bit}3%s2 to align anonymous field">,
10091019
InGroup<Padded>, DefaultIgnore;
10101020
def warn_padded_struct_size : Warning<
10111021
"padding size of %0 with %1 %select{byte|bit}2%s1 to alignment boundary">,

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",
5454
[SingleBitBitFieldConstantConversion]>;
5555
def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
5656
def BitFieldWidth : DiagGroup<"bitfield-width">;
57-
def BitFieldType : DiagGroup<"bitfield-type">;
5857
def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
5958
def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
6059
def CompoundTokenSplit : DiagGroup<"compound-token-split",
@@ -586,7 +585,8 @@ def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
586585
def OrderedCompareFunctionPointers : DiagGroup<"ordered-compare-function-pointers">;
587586
def PackedNonPod : DiagGroup<"packed-non-pod">;
588587
def Packed : DiagGroup<"packed", [PackedNonPod]>;
589-
def Padded : DiagGroup<"padded">;
588+
def PaddedBitField : DiagGroup<"padded-bitfield">;
589+
def Padded : DiagGroup<"padded", [PaddedBitField]>;
590590
def UnalignedAccess : DiagGroup<"unaligned-access">;
591591

592592
def PessimizingMove : DiagGroup<"pessimizing-move">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,9 +3167,6 @@ def err_invalid_branch_protection_spec : Error<
31673167
"invalid or misplaced branch protection specification '%0'">;
31683168
def warn_unsupported_branch_protection_spec : Warning<
31693169
"unsupported branch protection specification '%0'">, InGroup<BranchProtection>;
3170-
def warn_attribute_underlying_type_mismatch : Warning<
3171-
"underlying type %0 of enumeration %1 doesn't match bit-field type %2">,
3172-
InGroup<BitFieldType>;
31733170

31743171
def warn_unsupported_target_attribute
31753172
: Warning<"%select{unsupported|duplicate|unknown}0%select{| CPU|"

clang/include/clang/Driver/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,10 @@ def fswift_async_fp_EQ : Joined<["-"], "fswift-async-fp=">,
17351735
NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
17361736
NormalizedValues<["Auto", "Always", "Never"]>,
17371737
MarshallingInfoEnum<CodeGenOpts<"SwiftAsyncFramePointer">, "Always">;
1738+
def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
1739+
Group<f_clang_Group>, Visibility<[ClangOption, CC1Option]>,
1740+
MetaVarName<"<version>">,
1741+
HelpText<"Specify the Swift version to use when filtering API notes">;
17381742

17391743
defm addrsig : BoolFOption<"addrsig",
17401744
CodeGenOpts<"Addrsig">, DefaultFalse,
@@ -4205,6 +4209,9 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, Group<clang_i_Group>,
42054209
def index_header_map : Flag<["-"], "index-header-map">,
42064210
Visibility<[ClangOption, CC1Option]>,
42074211
HelpText<"Make the next included directory (-I or -F) an indexer header map">;
4212+
def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, Group<clang_i_Group>,
4213+
Visibility<[ClangOption, CC1Option]>,
4214+
HelpText<"Add directory to the API notes search path referenced by module name">, MetaVarName<"<directory>">;
42084215
def idirafter : JoinedOrSeparate<["-"], "idirafter">, Group<clang_i_Group>,
42094216
Visibility<[ClangOption, CC1Option]>,
42104217
HelpText<"Add directory to AFTER include search path">;

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
1010
#define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
1111

12+
#include "clang/APINotes/APINotesOptions.h"
1213
#include "clang/Basic/CodeGenOptions.h"
1314
#include "clang/Basic/DiagnosticOptions.h"
1415
#include "clang/Basic/FileSystemOptions.h"
@@ -92,6 +93,9 @@ class CompilerInvocationBase {
9293

9394
std::shared_ptr<MigratorOptions> MigratorOpts;
9495

96+
/// Options controlling API notes.
97+
std::shared_ptr<APINotesOptions> APINotesOpts;
98+
9599
/// Options controlling IRgen and the backend.
96100
std::shared_ptr<CodeGenOptions> CodeGenOpts;
97101

@@ -131,6 +135,7 @@ class CompilerInvocationBase {
131135
const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
132136
const AnalyzerOptions &getAnalyzerOpts() const { return *AnalyzerOpts; }
133137
const MigratorOptions &getMigratorOpts() const { return *MigratorOpts; }
138+
const APINotesOptions &getAPINotesOpts() const { return *APINotesOpts; }
134139
const CodeGenOptions &getCodeGenOpts() const { return *CodeGenOpts; }
135140
const FileSystemOptions &getFileSystemOpts() const { return *FSOpts; }
136141
const FrontendOptions &getFrontendOpts() const { return *FrontendOpts; }
@@ -226,6 +231,7 @@ class CompilerInvocation : public CompilerInvocationBase {
226231
using CompilerInvocationBase::getPreprocessorOpts;
227232
using CompilerInvocationBase::getAnalyzerOpts;
228233
using CompilerInvocationBase::getMigratorOpts;
234+
using CompilerInvocationBase::getAPINotesOpts;
229235
using CompilerInvocationBase::getCodeGenOpts;
230236
using CompilerInvocationBase::getFileSystemOpts;
231237
using CompilerInvocationBase::getFrontendOpts;
@@ -242,6 +248,7 @@ class CompilerInvocation : public CompilerInvocationBase {
242248
PreprocessorOptions &getPreprocessorOpts() { return *PPOpts; }
243249
AnalyzerOptions &getAnalyzerOpts() { return *AnalyzerOpts; }
244250
MigratorOptions &getMigratorOpts() { return *MigratorOpts; }
251+
APINotesOptions &getAPINotesOpts() { return *APINotesOpts; }
245252
CodeGenOptions &getCodeGenOpts() { return *CodeGenOpts; }
246253
FileSystemOptions &getFileSystemOpts() { return *FSOpts; }
247254
FrontendOptions &getFrontendOpts() { return *FrontendOpts; }
@@ -368,6 +375,7 @@ class CowCompilerInvocation : public CompilerInvocationBase {
368375
PreprocessorOptions &getMutPreprocessorOpts();
369376
AnalyzerOptions &getMutAnalyzerOpts();
370377
MigratorOptions &getMutMigratorOpts();
378+
APINotesOptions &getMutAPINotesOpts();
371379
CodeGenOptions &getMutCodeGenOpts();
372380
FileSystemOptions &getMutFileSystemOpts();
373381
FrontendOptions &getMutFrontendOpts();

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,19 +2297,22 @@ void ItaniumRecordLayoutBuilder::CheckFieldPadding(
22972297
PadSize = PadSize / CharBitNum;
22982298
InBits = false;
22992299
}
2300-
if (D->getIdentifier())
2301-
Diag(D->getLocation(), diag::warn_padded_struct_field)
2300+
if (D->getIdentifier()) {
2301+
auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_bitfield
2302+
: diag::warn_padded_struct_field;
2303+
Diag(D->getLocation(), Diagnostic)
23022304
<< getPaddingDiagFromTagKind(D->getParent()->getTagKind())
2303-
<< Context.getTypeDeclType(D->getParent())
2304-
<< PadSize
2305+
<< Context.getTypeDeclType(D->getParent()) << PadSize
23052306
<< (InBits ? 1 : 0) // (byte|bit)
23062307
<< D->getIdentifier();
2307-
else
2308-
Diag(D->getLocation(), diag::warn_padded_struct_anon_field)
2308+
} else {
2309+
auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_anon_bitfield
2310+
: diag::warn_padded_struct_anon_field;
2311+
Diag(D->getLocation(), Diagnostic)
23092312
<< getPaddingDiagFromTagKind(D->getParent()->getTagKind())
2310-
<< Context.getTypeDeclType(D->getParent())
2311-
<< PadSize
2313+
<< Context.getTypeDeclType(D->getParent()) << PadSize
23122314
<< (InBits ? 1 : 0); // (byte|bit)
2315+
}
23132316
}
23142317
if (isPacked && Offset != UnpackedOffset) {
23152318
HasPackedField = true;

0 commit comments

Comments
 (0)