Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoBump] Merge with be6248a4 (Jun 11) (68) #332

Closed
wants to merge 97 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
be06761
[clang][cmake] Fixes for PGO builds when invoking ninja twice (#92591)
tstellar Jun 10, 2024
4f41698
[NFC][msan] Prepare function to extract main logic (#94880)
vitalybuka Jun 10, 2024
983bf65
[NFC][msan] Extract `handleSelectLikeInst` (#94881)
vitalybuka Jun 10, 2024
d3c0ed3
[NFCI][metadata][LibCallsShrinkWrap] Use create{Unlikely,Likely}Branc…
vitalybuka Jun 10, 2024
85c78d4
[libc][stdlib] Add Block class (#94407)
PiJoules Jun 10, 2024
d474976
[mlir][sparse] fix missing cmake dependencies. (#95034)
Jun 10, 2024
83da21a
[VPlan] Generalize type inference for binary VPInstructions (NFC).
fhahn Jun 10, 2024
fade04f
[Clang][Comments] Add argument parsing for @throw @throws @exception …
hdoc Jun 10, 2024
0babff9
[flang] Lower REDUCE intrinsic with no DIM argument and rank 1 (#94652)
clementval Jun 10, 2024
f50656c
[libc][math][c23] Add MPFR unit tests for {rint,lrint,llrint,lround,l…
overmighty Jun 10, 2024
3c8e0b8
[BOLT] Clean up DIEStreamer (NFC) (#95028)
kazutakahirata Jun 10, 2024
076a50a
[NFC][libc][stdlib] LLVM_LIBC_SRC_STDLIB_LDIV_H -> LLVM_LIBC_SRC_STDL…
PiJoules Jun 10, 2024
fd4a740
[libc][stdlib] Move LIBC_INLINE after template and before constexpr (…
PiJoules Jun 10, 2024
f3b212c
[flang][NFC] Remove debug printing
clementval Jun 10, 2024
bb2bf3a
[NFCI][metadata][clang] Use create{Unlikely,Likely}BranchWeights (#89…
vitalybuka Jun 10, 2024
1fe4f2d
[Inliner][test] Fix incorrect REQUIRE line in `inline-switch-default.…
mshockwave Jun 10, 2024
3aa41e0
[X86,MC] Remove two getPrevNode
MaskRay Jun 10, 2024
e2d539b
[memprof] Fix comment typos (NFC)
kazutakahirata Jun 10, 2024
48aebd4
Revert "[AArch64] Decouple feature dependency expansion. (#94279)" (#…
labrinea Jun 10, 2024
46e41c8
[mlir] Sanitize identifiers with leading symbol. (#94795)
dtzSiFive Jun 11, 2024
1737814
[libc][stdlib] Add freelist class (#95041)
PiJoules Jun 11, 2024
189d471
[clang] Reland Add tanf16 builtin and support for tan constrained in…
farzonl Jun 11, 2024
c4f8ae6
[LLVM][IR][Sanitizers] Add sanitize_numerical_stability attribute (#9…
alexander-shaposhnikov Jun 11, 2024
abbb24b
MCSection: Remove unused reverse iterators
MaskRay Jun 11, 2024
5275aed
Reland "[X86] Assign AVX10_1 feature priority to align with gcc. (#94…
FreddyLeaf Jun 11, 2024
8e12f31
[mlir][gpu] Update LaunchFuncOp lowering in GPU to LLVM (#94991)
fabianmcg Jun 11, 2024
cb63abc
[MC] Remove getFragmentList uses. NFC
MaskRay Jun 11, 2024
69e9e77
[clang] Replace X && isa<Y>(X) with isa_and_nonnull<Y>(X). NFC (#94987)
samolisov Jun 11, 2024
39cf880
[libc][stdlib] Change old unsigned short variables to size_t (#95065)
PiJoules Jun 11, 2024
1934208
[lldb] NFC add comments and test case for ObjectFileMachO delay-init …
jasonmolenda Jun 11, 2024
6ffdcfa
[flang] Lower REDUCE intrinsic with DIM argument (#94771)
clementval Jun 11, 2024
690480f
[PAC][AArch64] Lower ptrauth constants in data (#94240)
kovdan01 Jun 11, 2024
0bc33f4
[AMDGPU] Update tests for last-use in global/scratch/flat/buffer load…
mariusz-sikora-at-amd Jun 11, 2024
48f8130
[Clang][Sanitizers] Add numerical sanitizer (#93783)
alexander-shaposhnikov Jun 11, 2024
41c650e
[clang] Don't use -Wno-nested-anon-types on GCC (#95029)
mstorsjo Jun 11, 2024
607afa0
Revert "[llvm][IR] Extend BranchWeightMetadata to track provenance of…
ilovepi Jun 11, 2024
1bebb99
[RISCV] Add B extension (#76893)
wangpc-pp Jun 11, 2024
34033dc
[clangd] Use clang_target_link_libraries() for clang libs (#94937)
nikic Jun 11, 2024
bfa8150
Explain partial byte extraction logic. (#92868)
jreiffers Jun 11, 2024
876c620
[RISCV][MC] Warn if SEW/LMUL may not be compatible
wangpc-pp Jun 11, 2024
2825342
[clang][dataflow] Handle `AtomicExpr` in `ResultObjectVisitor`. (#94963)
martinboehme Jun 11, 2024
05e87a5
Reland "[MC][NFC] Make ELFUniquingMap a StringMap (#95006)" (#95030)
aengelke Jun 11, 2024
275196d
[clang][nullability] Don't return null fields from `getReferencedDecl…
martinboehme Jun 11, 2024
e9a3623
[CodeGen] Preserved additional analyses in StackSlotColoring pass. (#…
vg0204 Jun 11, 2024
4cff320
[flang] lower LBOUND for assumed-rank arrays (#94995)
jeanPerier Jun 11, 2024
b64cf38
[flang][debug] Support assumed shape arrays. (#94644)
abidh Jun 11, 2024
baad1b8
[lldb] Add a test for lea_rsp_pattern_p to x86 unwinder (NFC) (#94852)
xgupta Jun 11, 2024
bd9a525
[AArch64] Fix gcc "enumeral and non-enumeral type" warning
mikaelholmen Jun 11, 2024
b1fe03f
[APFloat] Add APFloat support for FP6 data types (#94735)
durga4github Jun 11, 2024
c63a622
[AArch64] Disable red-zone when lowering Q-reg copy through memory. (…
sdesmalen-arm Jun 11, 2024
affd73a
MathExtras: MulOverflow: use builtin when available (NFC) (#95046)
Superty Jun 11, 2024
79ce70b
[NFC] Mitigate pointless copies (#95052)
bradenhelmer Jun 11, 2024
35ddc17
[StackSafety] Make lit tests compatible with lit's internal shell. NF…
jayfoad Jun 11, 2024
529b43c
[clang][Interp] Refine diagnostics for casts from void*
tbaederr Jun 11, 2024
ec81c9b
[clang] Remove a redundant check in Mangle. NFC (#95071)
samolisov Jun 11, 2024
995ba4a
[CostModel][X86] Adjust ABS scalar SizeLatency cost to 3uops
RKSimon Jun 10, 2024
e5bdb7a
[InstCombine] fold ldexp(x, sext(i1 y)) to fmul x, (select y, 0.5, 1.…
c8ef Jun 11, 2024
9dfd076
[test] Fix documentation of %{fs-sep} et al (#95088)
jayfoad Jun 11, 2024
2ca8c85
[X86] is_fpclass.ll - add NDD test coverage
RKSimon Jun 11, 2024
214ff50
[X86] Add AMXProgModel to YAML serialization (#94988)
aengelke Jun 11, 2024
fc6e97c
[MC][X86] Avoid copying MCInst in emitInstrEnd (#94947)
aengelke Jun 11, 2024
2dc2290
Revert new debug info format commits:
SLTozer Jun 11, 2024
424188a
[clang][Interp][test] Add test for void* diagnostics changes
tbaederr Jun 11, 2024
00262ab
[X86] Pull out repeated SDLoc in various ADD/SUB/XOR folds. NFC.
RKSimon Jun 11, 2024
264bcbe
[InstCombine] Add #38139 test coverage
RKSimon Jun 11, 2024
efbd64c
[mlir][arith] Delete unnecessary error logs (#94970)
cxy-1993 Jun 11, 2024
9b225d0
Fix complex abs with nnan/ninf. (#95080)
jreiffers Jun 11, 2024
fa9745e
[clang][Interp][NFC] Remove unneeded opcode initializers
tbaederr Jun 11, 2024
3f88311
[Driver] Rearrange some Apple version testing (#94514)
pogo59 Jun 11, 2024
a141a28
[SPIR-V] Fix flakiness during switch generation. (#95001)
Keenuts Jun 11, 2024
ca920bb
[MLIR][Flang][DebugInfo] Set debug info format in MLIR->IR translatio…
SLTozer Jun 11, 2024
546c816
[clang-tidy] Improve sizeof(pointer) handling in bugprone-sizeof-expr…
NagyDonat Jun 11, 2024
d4b8b72
[CodeGen][MachineLICM] Use RegUnits in HoistRegionPostRA (#94608)
Pierre-vh Jun 11, 2024
ffc3a6b
[libc++] Fix endianness for algorithm mismatch (#93082)
zibi2 Jun 11, 2024
8c5d9c7
Revert "[MLIR][Flang][DebugInfo] Set debug info format in MLIR->IR tr…
SLTozer Jun 11, 2024
a45080f
[AMDGPU] Document amdgpu-as in AMDGPUUsage (#94335)
Pierre-vh Jun 11, 2024
a2bc50a
AMDGPU: Add more tests for vector typed atomicrmw fadd
arsenm Jun 7, 2024
460408f
Reapply "[MLIR][Flang][DebugInfo] Set debug info format in MLIR->IR t…
SLTozer Jun 11, 2024
3cc2710
[MLIR][Flang][DebugInfo] Convert debug format in MLIR translators
SLTozer Jun 11, 2024
d4c6478
[mlir][vector] Update tests for collapse 1/n (nfc) (#94490)
banach-space Jun 11, 2024
1bae108
[clang-tidy] fix false positives for the functions with the same name…
HerrCai0907 Jun 11, 2024
da5f45f
[ConstantFolding] Preserve nowrap flags in gep of gep fold
nikic Jun 4, 2024
32add24
Fix test to have correct requirements (#95106)
pogo59 Jun 11, 2024
e805b77
[clang][Interp] Support ObjCEncodeExprs
tbaederr Jun 11, 2024
400d4fd
[RemoveDIs] Update all docs to use debug records (#91768)
SLTozer Jun 11, 2024
2b15fb1
[gold] Don't pass StringRef to message() (#95083)
nikic Jun 11, 2024
837dc54
[CodeGen][NewPM] Split `MachineDominatorTree` into a concrete analysi…
paperchalice Jun 11, 2024
a7d28f5
[X86] early-ifcvt-remarks.ll - add codegen checks
RKSimon Jun 11, 2024
bc5ced5
Updated the annotations of Python bindings (#92733)
superbobry Jun 11, 2024
37e9bf9
[bazel] Add missing dependency for 3cc2710e0dd53bb82742904fa13014018a…
d0k Jun 11, 2024
2eb60e2
[Offload][NFCI] Initialize the KernelArgsTy to default values (#95117)
jdoerfert Jun 11, 2024
d83f37f
Revert#2 "[MLIR][Flang][DebugInfo] Set debug info format in MLIR->IR …
SLTozer Jun 11, 2024
c0e1ad7
[lldb] Skip declaration DIEs in the debug_names index (#94744)
labath Jun 11, 2024
1df3798
[X86] early-ifcvt-remarks.ll - use i64 arithmetic to ensure ifcvt doe…
RKSimon Jun 11, 2024
464eb64
[X86] SimplifyDemandedBitsForTargetNode - add basic X86ISD::CMOV hand…
RKSimon Jun 11, 2024
be6248a
[Bazel] Layering fix for 65310f34d7edf7924ca4cbe7df836770669f70dc
steelannelida Jun 11, 2024
a5e2e47
[AutoBump] Merge with be6248a4 (Jun 11)
mgehre-amd Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 7 additions & 8 deletions bolt/lib/Rewrite/DWARFRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ class DIEStreamer : public DwarfStreamer {
}

public:
DIEStreamer(DIEBuilder *DIEBldr, DWARFRewriter &Rewriter,
GDBIndex &GDBIndexSection,
DIEStreamer(DIEBuilder *DIEBldr, GDBIndex &GDBIndexSection,
DWARFLinkerBase::OutputFileType OutFileType,
raw_pwrite_stream &OutFile,
DWARFLinkerBase::MessageHandlerTy Warning)
Expand Down Expand Up @@ -460,11 +459,11 @@ static std::optional<uint64_t> getAsAddress(const DWARFUnit &DU,
static std::unique_ptr<DIEStreamer>
createDIEStreamer(const Triple &TheTriple, raw_pwrite_stream &OutFile,
StringRef Swift5ReflectionSegmentName, DIEBuilder &DIEBldr,
DWARFRewriter &Rewriter, GDBIndex &GDBIndexSection) {
GDBIndex &GDBIndexSection) {

std::unique_ptr<DIEStreamer> Streamer = std::make_unique<DIEStreamer>(
&DIEBldr, Rewriter, GDBIndexSection,
DWARFLinkerBase::OutputFileType::Object, OutFile,
&DIEBldr, GDBIndexSection, DWARFLinkerBase::OutputFileType::Object,
OutFile,
[&](const Twine &Warning, StringRef Context, const DWARFDie *) {});
Error Err = Streamer->init(TheTriple, Swift5ReflectionSegmentName);
if (Err)
Expand Down Expand Up @@ -502,7 +501,7 @@ emitDWOBuilder(const std::string &DWOName, DIEBuilder &DWODIEBuilder,
auto TheTriple = std::make_unique<Triple>(File->makeTriple());
std::unique_ptr<DIEStreamer> Streamer =
createDIEStreamer(*TheTriple, *ObjOS, "DwoStreamerInitAug2",
DWODIEBuilder, Rewriter, GDBIndexSection);
DWODIEBuilder, GDBIndexSection);
DWARFRewriter::UnitMetaVectorType TUMetaVector;
DWARFRewriter::UnitMeta CUMI = {0, 0, 0};
if (SplitCU.getContext().getMaxDWOVersion() >= 5) {
Expand Down Expand Up @@ -733,7 +732,7 @@ void DWARFRewriter::updateDebugInfo() {
const object::ObjectFile *File = BC.DwCtx->getDWARFObj().getFile();
auto TheTriple = std::make_unique<Triple>(File->makeTriple());
std::unique_ptr<DIEStreamer> Streamer = createDIEStreamer(
*TheTriple, *ObjOS, "TypeStreamer", DIEBlder, *this, GDBIndexSection);
*TheTriple, *ObjOS, "TypeStreamer", DIEBlder, GDBIndexSection);
CUOffsetMap OffsetMap =
finalizeTypeSections(DIEBlder, *Streamer, GDBIndexSection);

Expand Down Expand Up @@ -1456,7 +1455,7 @@ CUOffsetMap DWARFRewriter::finalizeTypeSections(DIEBuilder &DIEBlder,
const object::ObjectFile *File = BC.DwCtx->getDWARFObj().getFile();
auto TheTriple = std::make_unique<Triple>(File->makeTriple());
std::unique_ptr<DIEStreamer> TypeStreamer = createDIEStreamer(
*TheTriple, *ObjOS, "TypeStreamer", DIEBlder, *this, GDBIndexSection);
*TheTriple, *ObjOS, "TypeStreamer", DIEBlder, GDBIndexSection);

// generate debug_info and CUMap
CUOffsetMap CUMap;
Expand Down
115 changes: 70 additions & 45 deletions clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
WarnOnSizeOfCompareToConstant(
Options.get("WarnOnSizeOfCompareToConstant", true)),
WarnOnSizeOfPointerToAggregate(
Options.get("WarnOnSizeOfPointerToAggregate", true)) {}
Options.get("WarnOnSizeOfPointerToAggregate", true)),
WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)) {}

void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
Expand All @@ -78,6 +79,7 @@ void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
WarnOnSizeOfCompareToConstant);
Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
WarnOnSizeOfPointerToAggregate);
Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
}

void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
Expand Down Expand Up @@ -127,17 +129,30 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
const auto ConstStrLiteralDecl =
varDecl(isDefinition(), hasType(hasCanonicalType(CharPtrType)),
hasInitializer(ignoringParenImpCasts(stringLiteral())));
const auto VarWithConstStrLiteralDecl = expr(
hasType(hasCanonicalType(CharPtrType)),
ignoringParenImpCasts(declRefExpr(hasDeclaration(ConstStrLiteralDecl))));
Finder->addMatcher(
sizeOfExpr(has(ignoringParenImpCasts(
expr(hasType(hasCanonicalType(CharPtrType)),
ignoringParenImpCasts(declRefExpr(
hasDeclaration(ConstStrLiteralDecl)))))))
sizeOfExpr(has(ignoringParenImpCasts(VarWithConstStrLiteralDecl)))
.bind("sizeof-charp"),
this);

// Detect sizeof(ptr) where ptr points to an aggregate (i.e. sizeof(&S)).
// Do not find it if RHS of a 'sizeof(arr) / sizeof(arr[0])' expression.
if (WarnOnSizeOfPointerToAggregate) {
// Detect sizeof(ptr) where ptr is a pointer (CWE-467).
//
// In WarnOnSizeOfPointerToAggregate mode only report cases when ptr points
// to an aggregate type or ptr is an expression that (implicitly or
// explicitly) casts an array to a pointer type. (These are more suspicious
// than other sizeof(ptr) expressions because they can appear as distorted
// forms of the common sizeof(aggregate) expressions.)
//
// To avoid false positives, the check doesn't report expressions like
// 'sizeof(pp[0])' and 'sizeof(*pp)' where `pp` is a pointer-to-pointer or
// array of pointers. (This filters out both `sizeof(arr) / sizeof(arr[0])`
// expressions and other cases like `p = realloc(p, newsize * sizeof(*p));`.)
//
// Moreover this generic message is suppressed in cases that are also matched
// by the more concrete matchers 'sizeof-this' and 'sizeof-charp'.
if (WarnOnSizeOfPointerToAggregate || WarnOnSizeOfPointer) {
const auto ArrayExpr =
ignoringParenImpCasts(hasType(hasCanonicalType(arrayType())));
const auto ArrayCastExpr = expr(anyOf(
Expand All @@ -149,32 +164,31 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {

const auto PointerToStructType =
hasUnqualifiedDesugaredType(pointerType(pointee(recordType())));
const auto PointerToStructExpr = expr(
hasType(hasCanonicalType(PointerToStructType)), unless(cxxThisExpr()));

const auto ArrayOfPointersExpr = ignoringParenImpCasts(
hasType(hasCanonicalType(arrayType(hasElementType(pointerType()))
.bind("type-of-array-of-pointers"))));
const auto ArrayOfSamePointersExpr =
ignoringParenImpCasts(hasType(hasCanonicalType(
arrayType(equalsBoundNode("type-of-array-of-pointers")))));
const auto PointerToStructTypeWithBinding =
type(PointerToStructType).bind("struct-type");
const auto PointerToStructExpr =
expr(hasType(hasCanonicalType(PointerToStructType)));

const auto PointerToDetectedExpr =
WarnOnSizeOfPointer
? expr(hasType(hasUnqualifiedDesugaredType(pointerType())))
: expr(anyOf(ArrayCastExpr, PointerToArrayExpr,
PointerToStructExpr));

const auto ZeroLiteral = ignoringParenImpCasts(integerLiteral(equals(0)));
const auto ArrayOfSamePointersZeroSubscriptExpr =
ignoringParenImpCasts(arraySubscriptExpr(
hasBase(ArrayOfSamePointersExpr), hasIndex(ZeroLiteral)));
const auto ArrayLengthExprDenom =
expr(hasParent(binaryOperator(hasOperatorName("/"),
hasLHS(ignoringParenImpCasts(sizeOfExpr(
has(ArrayOfPointersExpr)))))),
sizeOfExpr(has(ArrayOfSamePointersZeroSubscriptExpr)));
const auto SubscriptExprWithZeroIndex =
arraySubscriptExpr(hasIndex(ZeroLiteral));
const auto DerefExpr =
ignoringParenImpCasts(unaryOperator(hasOperatorName("*")));

Finder->addMatcher(
expr(sizeOfExpr(anyOf(
has(ignoringParenImpCasts(anyOf(
ArrayCastExpr, PointerToArrayExpr, PointerToStructExpr))),
has(PointerToStructType))),
unless(ArrayLengthExprDenom))
.bind("sizeof-pointer-to-aggregate"),
expr(sizeOfExpr(anyOf(has(ignoringParenImpCasts(
expr(PointerToDetectedExpr, unless(DerefExpr),
unless(SubscriptExprWithZeroIndex),
unless(VarWithConstStrLiteralDecl),
unless(cxxThisExpr())))),
has(PointerToStructTypeWithBinding))))
.bind("sizeof-pointer"),
this);
}

Expand Down Expand Up @@ -292,11 +306,17 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
diag(E->getBeginLoc(),
"suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
<< E->getSourceRange();
} else if (const auto *E =
Result.Nodes.getNodeAs<Expr>("sizeof-pointer-to-aggregate")) {
diag(E->getBeginLoc(),
"suspicious usage of 'sizeof(A*)'; pointer to aggregate")
<< E->getSourceRange();
} else if (const auto *E = Result.Nodes.getNodeAs<Expr>("sizeof-pointer")) {
if (Result.Nodes.getNodeAs<Type>("struct-type")) {
diag(E->getBeginLoc(),
"suspicious usage of 'sizeof(A*)' on pointer-to-aggregate type; did "
"you mean 'sizeof(A)'?")
<< E->getSourceRange();
} else {
diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
"that results in a pointer")
<< E->getSourceRange();
}
} else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
"sizeof-compare-constant")) {
diag(E->getOperatorLoc(),
Expand Down Expand Up @@ -332,18 +352,23 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
" numerator is not a multiple of denominator")
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
} else if (NumTy && DenomTy && NumTy == DenomTy) {
// FIXME: This message is wrong, it should not refer to sizeof "pointer"
// usage (and by the way, it would be to clarify all the messages).
diag(E->getOperatorLoc(),
"suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'")
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
} else if (PointedTy && DenomTy && PointedTy == DenomTy) {
diag(E->getOperatorLoc(),
"suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'")
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
} else if (NumTy && DenomTy && NumTy->isPointerType() &&
DenomTy->isPointerType()) {
diag(E->getOperatorLoc(),
"suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'")
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
} else if (!WarnOnSizeOfPointer) {
// When 'WarnOnSizeOfPointer' is enabled, these messages become redundant:
if (PointedTy && DenomTy && PointedTy == DenomTy) {
diag(E->getOperatorLoc(),
"suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'")
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
} else if (NumTy && DenomTy && NumTy->isPointerType() &&
DenomTy->isPointerType()) {
diag(E->getOperatorLoc(),
"suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'")
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
}
}
} else if (const auto *E =
Result.Nodes.getNodeAs<Expr>("sizeof-sizeof-expr")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SizeofExpressionCheck : public ClangTidyCheck {
const bool WarnOnSizeOfThis;
const bool WarnOnSizeOfCompareToConstant;
const bool WarnOnSizeOfPointerToAggregate;
const bool WarnOnSizeOfPointer;
};

} // namespace clang::tidy::bugprone
Expand Down
6 changes: 5 additions & 1 deletion clang-tools-extra/clangd/index/remote/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ if (CLANGD_ENABLE_REMOTE)
clangdRemoteIndexProto
clangdRemoteIndexServiceProto
clangdRemoteMarshalling
clangBasic
clangDaemon
clangdSupport

Expand All @@ -35,6 +34,11 @@ if (CLANGD_ENABLE_REMOTE)
clangdRemoteIndexServiceProto
)

clang_target_link_libraries(clangdRemoteIndex
PRIVATE
clangBasic
)

add_subdirectory(marshalling)
add_subdirectory(server)
add_subdirectory(monitor)
Expand Down
10 changes: 10 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ Changes in existing checks
<clang-tidy/checks/bugprone/optional-value-conversion>` check by eliminating
false positives resulting from use of optionals in unevaluated context.

- Improved :doc:`bugprone-sizeof-expression
<clang-tidy/checks/bugprone/sizeof-expression>` check by eliminating some
false positives and adding a new (off-by-default) option
`WarnOnSizeOfPointer` that reports all ``sizeof(pointer)`` expressions
(except for a few that are idiomatic).

- Improved :doc:`bugprone-suspicious-include
<clang-tidy/checks/bugprone/suspicious-include>` check by replacing the local
options `HeaderFileExtensions` and `ImplementationFileExtensions` by the
Expand Down Expand Up @@ -331,6 +337,10 @@ Changes in existing checks
<clang-tidy/checks/misc/header-include-cycle>` check by avoiding crash for self
include cycles.

- Improved :doc:`misc-include-cleaner
<clang-tidy/checks/misc/include-cleaner>` check by avoiding false positives for
the functions with the same name as standard library functions.

- Improved :doc:`misc-unused-using-decls
<clang-tidy/checks/misc/unused-using-decls>` check by replacing the local
option `HeaderFileExtensions` by the global option of the same name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ Options

.. option:: WarnOnSizeOfPointerToAggregate

When `true`, the check will warn on an expression like
``sizeof(expr)`` where the expression is a pointer
to aggregate. Default is `true`.
When `true`, the check will warn when the argument of ``sizeof`` is either a
pointer-to-aggregate type, an expression returning a pointer-to-aggregate
value or an expression that returns a pointer from an array-to-pointer
conversion (that may be implicit or explicit, for example ``array + 2`` or
``(int *)array``). Default is `true`.

.. option:: WarnOnSizeOfPointer

When `true`, the check will report all expressions where the argument of
``sizeof`` is an expression that produces a pointer (except for a few
idiomatic expressions that are probably intentional and correct).
This detects occurrences of CWE 467. Default is `false`.
8 changes: 6 additions & 2 deletions clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/Tooling/Inclusions/StandardLibrary.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
#include <utility>
#include <vector>

Expand All @@ -40,8 +41,11 @@ Hints declHints(const Decl *D) {
std::vector<Hinted<SymbolLocation>> locateDecl(const Decl &D) {
std::vector<Hinted<SymbolLocation>> Result;
// FIXME: Should we also provide physical locations?
if (auto SS = tooling::stdlib::Recognizer()(&D))
return {{*SS, Hints::CompleteSymbol}};
if (auto SS = tooling::stdlib::Recognizer()(&D)) {
Result.push_back({*SS, Hints::CompleteSymbol});
if (!D.hasBody())
return Result;
}
// FIXME: Signal foreign decls, e.g. a forward declaration not owned by a
// library. Some useful signals could be derived by checking the DeclContext.
// Most incidental forward decls look like:
Expand Down
11 changes: 11 additions & 0 deletions clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,17 @@ TEST_F(HeadersForSymbolTest, StandardHeaders) {
tooling::stdlib::Header::named("<assert.h>")));
}

TEST_F(HeadersForSymbolTest, NonStandardHeaders) {
Inputs.Code = "void assert() {}";
buildAST();
EXPECT_THAT(
headersFor("assert"),
// Respect the ordering from the stdlib mapping.
UnorderedElementsAre(physicalHeader("input.mm"),
tooling::stdlib::Header::named("<cassert>"),
tooling::stdlib::Header::named("<assert.h>")));
}

TEST_F(HeadersForSymbolTest, ExporterNoNameMatch) {
Inputs.Code = R"cpp(
#include "exporter/foo.h"
Expand Down
8 changes: 6 additions & 2 deletions clang-tools-extra/pseudo/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ add_clang_library(clangPseudo
Token.cpp

LINK_LIBS
clangBasic
clangLex
clangPseudoGrammar

DEPENDS
Expand All @@ -25,3 +23,9 @@ add_clang_library(clangPseudo
target_include_directories(clangPseudo INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
)

clang_target_link_libraries(clangPseudo
PRIVATE
clangBasic
clangLex
)
6 changes: 5 additions & 1 deletion clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ add_clang_library(clangPseudoCXX
cxx_gen

LINK_LIBS
clangBasic
clangPseudo
clangPseudoGrammar
)

clang_target_link_libraries(clangPseudoCXX
PRIVATE
clangBasic
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ int Test5() {

int sum = 0;
sum += sizeof(&S);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
sum += sizeof(__typeof(&S));
sum += sizeof(&TS);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
sum += sizeof(__typeof(&TS));
sum += sizeof(STRKWD MyStruct*);
sum += sizeof(__typeof(STRKWD MyStruct*));
sum += sizeof(TypedefStruct*);
sum += sizeof(__typeof(TypedefStruct*));
sum += sizeof(PTTS);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
sum += sizeof(PMyStruct);
sum += sizeof(PS);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
sum += sizeof(PS2);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer
sum += sizeof(&A10);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer

#ifdef __cplusplus
MyStruct &rS = S;
Expand Down
Loading