Skip to content

Commit ad8dd99

Browse files
committed
[AutoBump] Merge with 12f77e8 (Jun 13)
2 parents d266b33 + 12f77e8 commit ad8dd99

File tree

314 files changed

+200399
-19033
lines changed

Some content is hidden

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

314 files changed

+200399
-19033
lines changed

.github/workflows/libclang-python-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
python-version: ["3.7", "3.11"]
39+
python-version: ["3.8", "3.11"]
4040
uses: ./.github/workflows/llvm-project-tests.yml
4141
with:
4242
build_target: check-clang-python

clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static StringRef getControlFlowString(const Stmt &Stmt) {
231231
return "break";
232232
if (isa<CXXThrowExpr>(Stmt))
233233
return "throw";
234-
llvm_unreachable("Unknown control flow interruptor");
234+
llvm_unreachable("Unknown control flow interrupter");
235235
}
236236

237237
void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
@@ -247,12 +247,12 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
247247
return;
248248

249249
bool IsLastInScope = OuterScope->body_back() == If;
250-
StringRef ControlFlowInterruptor = getControlFlowString(*Interrupt);
250+
const StringRef ControlFlowInterrupter = getControlFlowString(*Interrupt);
251251

252252
if (!IsLastInScope && containsDeclInScope(Else)) {
253253
if (WarnOnUnfixable) {
254254
// Warn, but don't attempt an autofix.
255-
diag(ElseLoc, WarningMessage) << ControlFlowInterruptor;
255+
diag(ElseLoc, WarningMessage) << ControlFlowInterrupter;
256256
}
257257
return;
258258
}
@@ -264,7 +264,7 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
264264
// If the if statement is the last statement of its enclosing statements
265265
// scope, we can pull the decl out of the if statement.
266266
DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
267-
<< ControlFlowInterruptor
267+
<< ControlFlowInterrupter
268268
<< SourceRange(ElseLoc);
269269
if (checkInitDeclUsageInElse(If) != nullptr) {
270270
Diag << tooling::fixit::createReplacement(
@@ -288,7 +288,7 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
288288
removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
289289
} else if (WarnOnUnfixable) {
290290
// Warn, but don't attempt an autofix.
291-
diag(ElseLoc, WarningMessage) << ControlFlowInterruptor;
291+
diag(ElseLoc, WarningMessage) << ControlFlowInterrupter;
292292
}
293293
return;
294294
}
@@ -300,7 +300,7 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
300300
// If the if statement is the last statement of its enclosing statements
301301
// scope, we can pull the decl out of the if statement.
302302
DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
303-
<< ControlFlowInterruptor
303+
<< ControlFlowInterrupter
304304
<< SourceRange(ElseLoc);
305305
Diag << tooling::fixit::createReplacement(
306306
SourceRange(If->getIfLoc()),
@@ -312,13 +312,13 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
312312
removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
313313
} else if (WarnOnUnfixable) {
314314
// Warn, but don't attempt an autofix.
315-
diag(ElseLoc, WarningMessage) << ControlFlowInterruptor;
315+
diag(ElseLoc, WarningMessage) << ControlFlowInterrupter;
316316
}
317317
return;
318318
}
319319

320320
DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
321-
<< ControlFlowInterruptor << SourceRange(ElseLoc);
321+
<< ControlFlowInterrupter << SourceRange(ElseLoc);
322322
removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
323323
}
324324

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ Bug Fixes to C++ Support
846846
- Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
847847
- Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307),
848848
(#GH88081), (#GH89496), (#GH90669) and (#GH91633).
849+
- Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368).
849850

850851
Bug Fixes to AST Handling
851852
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/SourceBasedCodeCoverage.rst

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,31 @@ MC/DC Instrumentation
484484
---------------------
485485

486486
When instrumenting for Modified Condition/Decision Coverage (MC/DC) using the
487-
clang option ``-fcoverage-mcdc``, users are limited to at most **six** leaf-level
488-
conditions in a boolean expression. A warning will be generated for boolean
489-
expressions that contain more than six, and they will not be instrumented for
490-
MC/DC.
487+
clang option ``-fcoverage-mcdc``, there are two hard limits.
488+
489+
The maximum number of terms is limited to 32767, which is practical for
490+
handwritten expressions. To be more restrictive in order to enforce coding rules,
491+
use ``-Xclang -fmcdc-max-conditions=n``. Expressions with exceeded condition
492+
counts ``n`` will generate warnings and will be excluded in the MC/DC coverage.
493+
494+
The number of test vectors (the maximum number of possible combinations of
495+
expressions) is limited to 2,147,483,646. In this case, approximately
496+
256MiB (==2GiB/8) is used to record test vectors.
497+
498+
To reduce memory usage, users can limit the maximum number of test vectors per
499+
expression with ``-Xclang -fmcdc-max-test-vectors=m``.
500+
If the number of test vectors resulting from the analysis of an expression
501+
exceeds ``m``, a warning will be issued and the expression will be excluded
502+
from the MC/DC coverage.
503+
504+
The number of test vectors ``m``, for ``n`` terms in an expression, can be
505+
``m <= 2^n`` in the theoretical worst case, but is usually much smaller.
506+
In simple cases, such as expressions consisting of a sequence of single
507+
operators, ``m == n+1``. For example, ``(a && b && c && d && e && f && g)``
508+
requires 8 test vectors.
509+
510+
Expressions such as ``((a0 && b0) || (a1 && b1) || ...)`` can cause the
511+
number of test vectors to increase exponentially.
491512

492513
Also, if a boolean expression is embedded in the nest of another boolean
493514
expression but separated by a non-logical operator, this is also not supported.

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
223223
CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
224224
///< regions.
225225
CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code coverage criteria.
226+
VALUE_CODEGENOPT(MCDCMaxConds, 16, 32767) ///< MC/DC Maximum conditions.
227+
VALUE_CODEGENOPT(MCDCMaxTVs, 32, 0x7FFFFFFE) ///< MC/DC Maximum test vectors.
226228

227229
/// If -fpcc-struct-return or -freg-struct-return is specified.
228230
ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, SRCK_Default)

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,14 @@ defm mcdc_coverage : BoolFOption<"coverage-mcdc",
17901790
"Enable MC/DC criteria when generating code coverage">,
17911791
NegFlag<SetFalse, [], [ClangOption], "Disable MC/DC coverage criteria">,
17921792
BothFlags<[], [ClangOption, CLOption]>>;
1793+
def fmcdc_max_conditions_EQ : Joined<["-"], "fmcdc-max-conditions=">,
1794+
Group<f_Group>, Visibility<[CC1Option]>,
1795+
HelpText<"Maximum number of conditions in MC/DC coverage">,
1796+
MarshallingInfoInt<CodeGenOpts<"MCDCMaxConds">, "32767">;
1797+
def fmcdc_max_test_vectors_EQ : Joined<["-"], "fmcdc-max-test-vectors=">,
1798+
Group<f_Group>, Visibility<[CC1Option]>,
1799+
HelpText<"Maximum number of test vectors in MC/DC coverage">,
1800+
MarshallingInfoInt<CodeGenOpts<"MCDCMaxTVs">, "0x7FFFFFFE">;
17931801
def fprofile_generate : Flag<["-"], "fprofile-generate">,
17941802
Group<f_Group>, Visibility<[ClangOption, CLOption]>,
17951803
HelpText<"Generate instrumented code to collect execution counts into default.profraw (overridden by LLVM_PROFILE_FILE env var)">;

clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ class MemRegionManager {
15031503
/// associated element type, index, and super region.
15041504
const ElementRegion *getElementRegion(QualType elementType, NonLoc Idx,
15051505
const SubRegion *superRegion,
1506-
ASTContext &Ctx);
1506+
const ASTContext &Ctx);
15071507

15081508
const ElementRegion *getElementRegionWithSuper(const ElementRegion *ER,
15091509
const SubRegion *superRegion) {

clang/lib/AST/ExprConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14014,8 +14014,8 @@ bool IntExprEvaluator::VisitUnaryExprOrTypeTraitExpr(
1401414014
QualType Ty = E->getTypeOfArgument();
1401514015
// If the vector has a fixed size, we can determine the number of elements
1401614016
// at compile time.
14017-
if (Ty->isVectorType())
14018-
return Success(Ty->castAs<VectorType>()->getNumElements(), E);
14017+
if (const auto *VT = Ty->getAs<VectorType>())
14018+
return Success(VT->getNumElements(), E);
1401914019

1402014020
assert(Ty->isSizelessVectorType());
1402114021
if (Info.InConstantContext)

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
343343
}
344344

345345
case CK_IntegralToBoolean:
346+
case CK_BooleanToSignedIntegral:
346347
case CK_IntegralCast: {
347348
if (DiscardResult)
348349
return this->discard(SubExpr);
@@ -362,7 +363,12 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
362363

363364
if (FromT == ToT)
364365
return true;
365-
return this->emitCast(*FromT, *ToT, CE);
366+
if (!this->emitCast(*FromT, *ToT, CE))
367+
return false;
368+
369+
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
370+
return this->emitNeg(*ToT, CE);
371+
return true;
366372
}
367373

368374
case CK_PointerToBoolean:
@@ -1201,6 +1207,23 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
12011207
}
12021208

12031209
if (T->isArrayType()) {
1210+
// Prepare composite return value.
1211+
if (!Initializing) {
1212+
if (GlobalDecl) {
1213+
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
1214+
if (!GlobalIndex)
1215+
return false;
1216+
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
1217+
return false;
1218+
} else {
1219+
std::optional<unsigned> LocalIndex = allocateLocal(E);
1220+
if (!LocalIndex)
1221+
return false;
1222+
if (!this->emitGetPtrLocal(*LocalIndex, E))
1223+
return false;
1224+
}
1225+
}
1226+
12041227
unsigned ElementIndex = 0;
12051228
for (const Expr *Init : Inits) {
12061229
if (!this->visitArrayElemInit(ElementIndex, Init))

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
167167
PGOHash Hash;
168168
/// The map of statements to counters.
169169
llvm::DenseMap<const Stmt *, unsigned> &CounterMap;
170-
/// The next bitmap byte index to assign.
171-
unsigned NextMCDCBitmapIdx;
172170
/// The state of MC/DC Coverage in this function.
173171
MCDC::State &MCDCState;
174172
/// Maximum number of supported MC/DC conditions in a boolean expression.
@@ -183,7 +181,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
183181
MCDC::State &MCDCState, unsigned MCDCMaxCond,
184182
DiagnosticsEngine &Diag)
185183
: NextCounter(0), Hash(HashVersion), CounterMap(CounterMap),
186-
NextMCDCBitmapIdx(0), MCDCState(MCDCState), MCDCMaxCond(MCDCMaxCond),
184+
MCDCState(MCDCState), MCDCMaxCond(MCDCMaxCond),
187185
ProfileVersion(ProfileVersion), Diag(Diag) {}
188186

189187
// Blocks and lambdas are handled as separate functions, so we need not
@@ -314,11 +312,8 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
314312
return true;
315313
}
316314

317-
// Otherwise, allocate the number of bytes required for the bitmap
318-
// based on the number of conditions. Must be at least 1-byte long.
319-
MCDCState.DecisionByStmt[BinOp].BitmapIdx = NextMCDCBitmapIdx;
320-
unsigned SizeInBits = std::max<unsigned>(1L << NumCond, CHAR_BIT);
321-
NextMCDCBitmapIdx += SizeInBits / CHAR_BIT;
315+
// Otherwise, allocate the Decision.
316+
MCDCState.DecisionByStmt[BinOp].BitmapIdx = 0;
322317
}
323318
return true;
324319
}
@@ -1083,7 +1078,9 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
10831078
// for most embedded applications. Setting a maximum value prevents the
10841079
// bitmap footprint from growing too large without the user's knowledge. In
10851080
// the future, this value could be adjusted with a command-line option.
1086-
unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 6 : 0;
1081+
unsigned MCDCMaxConditions =
1082+
(CGM.getCodeGenOpts().MCDCCoverage ? CGM.getCodeGenOpts().MCDCMaxConds
1083+
: 0);
10871084

10881085
RegionCounterMap.reset(new llvm::DenseMap<const Stmt *, unsigned>);
10891086
RegionMCDCState.reset(new MCDC::State);
@@ -1099,7 +1096,6 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
10991096
Walker.TraverseDecl(const_cast<CapturedDecl *>(CD));
11001097
assert(Walker.NextCounter > 0 && "no entry counter mapped for decl");
11011098
NumRegionCounters = Walker.NextCounter;
1102-
RegionMCDCState->BitmapBytes = Walker.NextMCDCBitmapIdx;
11031099
FunctionHash = Walker.Hash.finalize();
11041100
}
11051101

@@ -1232,7 +1228,7 @@ void CodeGenPGO::emitMCDCParameters(CGBuilderTy &Builder) {
12321228
// anything.
12331229
llvm::Value *Args[3] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
12341230
Builder.getInt64(FunctionHash),
1235-
Builder.getInt32(RegionMCDCState->BitmapBytes)};
1231+
Builder.getInt32(RegionMCDCState->BitmapBits)};
12361232
Builder.CreateCall(
12371233
CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_parameters), Args);
12381234
}
@@ -1250,6 +1246,11 @@ void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder,
12501246
if (DecisionStateIter == RegionMCDCState->DecisionByStmt.end())
12511247
return;
12521248

1249+
// Don't create tvbitmap_update if the record is allocated but excluded.
1250+
// Or `bitmap |= (1 << 0)` would be wrongly executed to the next bitmap.
1251+
if (DecisionStateIter->second.Indices.size() == 0)
1252+
return;
1253+
12531254
// Extract the offset of the global bitmap associated with this expression.
12541255
unsigned MCDCTestVectorBitmapOffset = DecisionStateIter->second.BitmapIdx;
12551256
auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
@@ -1261,7 +1262,7 @@ void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder,
12611262
// index represents an executed test vector.
12621263
llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
12631264
Builder.getInt64(FunctionHash),
1264-
Builder.getInt32(RegionMCDCState->BitmapBytes),
1265+
Builder.getInt32(0), // Unused
12651266
Builder.getInt32(MCDCTestVectorBitmapOffset),
12661267
MCDCCondBitmapAddr.emitRawPointer(CGF)};
12671268
Builder.CreateCall(
@@ -1305,19 +1306,22 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy &Builder, const Expr *S,
13051306
// Extract the ID of the condition we are setting in the bitmap.
13061307
const auto &Branch = BranchStateIter->second;
13071308
assert(Branch.ID >= 0 && "Condition has no ID!");
1309+
assert(Branch.DecisionStmt);
13081310

1309-
auto *I8PtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
1311+
// Cancel the emission if the Decision is erased after the allocation.
1312+
const auto DecisionIter =
1313+
RegionMCDCState->DecisionByStmt.find(Branch.DecisionStmt);
1314+
if (DecisionIter == RegionMCDCState->DecisionByStmt.end())
1315+
return;
13101316

1311-
// Emit intrinsic that updates a dedicated temporary value on the stack after
1312-
// a condition is evaluated. After the set of conditions has been updated,
1313-
// the resulting value is used to update the boolean expression's bitmap.
1314-
llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
1315-
Builder.getInt64(FunctionHash),
1316-
Builder.getInt32(Branch.ID),
1317-
MCDCCondBitmapAddr.emitRawPointer(CGF), Val};
1318-
Builder.CreateCall(
1319-
CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_condbitmap_update),
1320-
Args);
1317+
const auto &TVIdxs = DecisionIter->second.Indices[Branch.ID];
1318+
1319+
auto *CurTV = Builder.CreateLoad(MCDCCondBitmapAddr,
1320+
"mcdc." + Twine(Branch.ID + 1) + ".cur");
1321+
auto *NewTV = Builder.CreateAdd(CurTV, Builder.getInt32(TVIdxs[true]));
1322+
NewTV = Builder.CreateSelect(
1323+
Val, NewTV, Builder.CreateAdd(CurTV, Builder.getInt32(TVIdxs[false])));
1324+
Builder.CreateStore(NewTV, MCDCCondBitmapAddr);
13211325
}
13221326

13231327
void CodeGenPGO::setValueProfilingFlag(llvm::Module &M) {

0 commit comments

Comments
 (0)