Skip to content

Commit cf2568d

Browse files
committed
64-bit source location
fix Reduce the Stmt size back to 8 bytes. Reduce the CallExpr size Fix the ObjCContainerDecl bit field Change the SourceLocation::UIntTy to uint64_t Update other SourceManager's getDecomposedSpellingLoc APIs, and fix many failing tests. Remaining failures: Clang :: Index/IBOutletCollection.m Clang :: Index/annotate-macro-args.m Clang :: Index/annotate-module.m Clang :: Index/annotate-tokens-pp.c Clang :: Index/annotate-tokens.c Clang :: Index/annotate-toplevel-in-objccontainer.m Clang :: Index/hidden-redecls.m Clang :: Index/index-module-with-vfs.m Clang :: Index/index-module.m Clang :: Index/index-pch-objc.m Clang :: Index/index-pch-with-module.m Clang :: Index/index-pch.cpp Clang :: Index/targeted-annotation.c Clang :: Lexer/SourceLocationsOverflow.c Clang-Unit :: ./AllClangUnitTests/PPMemoryAllocationsTest/PPMacroDefinesAllocations Clang-Unit :: ./AllClangUnitTests/SourceLocationEncoding/Individual Clang-Unit :: ./AllClangUnitTests/SourceLocationEncoding/Sequence Clang-Unit :: libclang/./libclangTests/14/53 Clang-Unit :: libclang/./libclangTests/45/53 Clang-Unit :: libclang/./libclangTests/47/53 Clang-Unit :: libclang/./libclangTests/48/53 Clang-Unit :: libclang/./libclangTests/49/53 Clang-Unit :: libclang/./libclangTests/50/53 Clang-Unit :: libclang/./libclangTests/52/53 Fix libclang failures Fix Rewrite APIs Fix PPMemoryAllocationsTest Fix SourceLocationEncodingTest More unsigned -> SourceLocation::UIntTy changes in the SourceManager APIs Update the type of std::pair<FileID, unsigned> in CIndex.cpp Fix SourceLocationEncodingTest Tweak the SourceLocation Implementation. The source location has a Bit which specify the number of bits used for the offset. 40 by default; Make MathExtra templates constexpr Test Bits=64 perf Try 48 bits No bitfields Fix CallExpr optimization. Test Bits=64 perf Switch Bits back to 40. Reduce SubstNonTypeTemplateParmExpr size: 48 -> 40 bytes Reduce OpaqueValueExpr: 32 -> 24 bytes Reduce CXXDependentScopeMemberExpr size: 88 -> 80 bytes Reduce DeclRefExpr size: 48 -> 40 bytes. by moving out the two source locations for CXXOpName from DeclarationNameLoc Fix some merge conflicts. Move the Loc back to the StmtBitFields if possible to save AST size. Improve getFildIDLocal binary search. Optimize binary search by using a dedicate offset table improve the cache performance Revert the static_assert change for ObjCContainerDeclBitfields. Fix the compile failures for include-cleaner. Fix clang-tidy build. Fix clangd unittest Fix windows build failures. unsigned long is 32 bits on MSVC More windows fix Change the underlying StmtBitField type to uint64_t, fix windows failures. So that the sizeof(Stmt) can stay with 8 bytes. More window fix Fix merge failures Update comments for SourceLocation. clang-format revert the Rewrite change. Don't change the FileIDAndOffset type. Revert the change in ObjCContainerDeclBitfields Revert the changei n HTMLReport.cpp Revert the unsigned -> UIntTy change in Diagnostic.h Revert the unsigned->UIntTy change in SourceManager. revert the binary optimization change.
1 parent 7fea83e commit cf2568d

Some content is hidden

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

46 files changed

+663
-439
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ struct CognitiveComplexity final {
127127
// https://sonarcloud.io/projects?languages=c%2Ccpp&size=5 we can estimate:
128128
// value ~20 would result in no allocs for 98% of functions, ~12 for 96%, ~10
129129
// for 91%, ~8 for 88%, ~6 for 84%, ~4 for 77%, ~2 for 64%, and ~1 for 37%.
130-
static_assert(sizeof(Detail) <= 8,
130+
static_assert(sizeof(Detail) <= 16,
131131
"Since we use SmallVector to minimize the amount of "
132132
"allocations, we also need to consider the price we pay for "
133133
"that in terms of stack usage. "
134134
"Thus, it is good to minimize the size of the Detail struct.");
135-
SmallVector<Detail, DefaultLimit> Details; // 25 elements is 200 bytes.
135+
SmallVector<Detail, DefaultLimit> Details; // 25 elements is 400 bytes.
136136
// Yes, 25 is a magic number. This is the seemingly-sane default for the
137137
// upper limit for function cognitive complexity. Thus it would make sense
138138
// to avoid allocations for any function that does not violate the limit.

clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,9 @@ TEST(SourceCodeTests, isSpelledInSource) {
829829
// FIXME: Should it return false on SourceLocation()? Does it matter?
830830
EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM));
831831
EXPECT_FALSE(isSpelledInSource(
832-
SourceLocation::getFromRawEncoding(SourceLocation::UIntTy(1 << 31)), SM));
832+
SourceLocation::getFromRawEncoding(
833+
SourceLocation::UIntTy(1ULL << (SourceLocation::Bits - 1))),
834+
SM));
833835
}
834836

835837
struct IncrementalTestStep {

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,6 +3356,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
33563356
getTrivialTypeSourceInfo(QualType T,
33573357
SourceLocation Loc = SourceLocation()) const;
33583358

3359+
CXXOperatorSourceInfo *getCXXOperatorSourceInfo(SourceRange R) const;
3360+
33593361
/// Add a deallocation callback that will be invoked when the
33603362
/// ASTContext is destroyed.
33613363
///

clang/include/clang/AST/DeclBase.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,17 +1952,13 @@ class DeclContext {
19521952
friend class ObjCContainerDecl;
19531953
/// For the bits in DeclContextBitfields
19541954
LLVM_PREFERRED_TYPE(DeclContextBitfields)
1955-
uint32_t : NumDeclContextBits;
1955+
uint64_t : NumDeclContextBits;
19561956

1957-
// Not a bitfield but this saves space.
1958-
// Note that ObjCContainerDeclBitfields is full.
1959-
SourceLocation AtStart;
1957+
uint64_t AtStart: SourceLocation::Bits;
19601958
};
19611959

19621960
/// Number of inherited and non-inherited bits in ObjCContainerDeclBitfields.
1963-
/// Note that here we rely on the fact that SourceLocation is 32 bits
1964-
/// wide. We check this with the static_assert in the ctor of DeclContext.
1965-
enum { NumObjCContainerDeclBits = 64 };
1961+
enum { NumObjCContainerDeclBits = NumDeclContextBits + SourceLocation::Bits };
19661962

19671963
/// Stores the bits used by LinkageSpecDecl.
19681964
/// If modified NumLinkageSpecDeclBits and the accessor

clang/include/clang/AST/DeclObjC.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,10 +1090,12 @@ class ObjCContainerDecl : public NamedDecl, public DeclContext {
10901090
/// Note, the superclass's properties are not included in the list.
10911091
virtual void collectPropertiesToImplement(PropertyMap &PM) const {}
10921092

1093-
SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; }
1093+
SourceLocation getAtStartLoc() const {
1094+
return SourceLocation::getFromRawEncoding(ObjCContainerDeclBits.AtStart);
1095+
}
10941096

10951097
void setAtStartLoc(SourceLocation Loc) {
1096-
ObjCContainerDeclBits.AtStart = Loc;
1098+
ObjCContainerDeclBits.AtStart = Loc.getRawEncoding();
10971099
}
10981100

10991101
// Marks the end of the container.

clang/include/clang/AST/DeclarationName.h

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,11 @@ class DeclarationNameTable {
682682
DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II);
683683
};
684684

685+
struct CXXOperatorSourceInfo {
686+
SourceLocation BeginOpNameLoc;
687+
SourceLocation EndOpNameLoc;
688+
};
689+
685690
/// DeclarationNameLoc - Additional source/type location info
686691
/// for a declaration name. Needs a DeclarationName in order
687692
/// to be interpreted correctly.
@@ -698,8 +703,7 @@ class DeclarationNameLoc {
698703

699704
// The location (if any) of the operator keyword is stored elsewhere.
700705
struct CXXOpName {
701-
SourceLocation BeginOpNameLoc;
702-
SourceLocation EndOpNameLoc;
706+
CXXOperatorSourceInfo *OInfo;
703707
};
704708

705709
// The location (if any) of the operator keyword is stored elsewhere.
@@ -719,11 +723,6 @@ class DeclarationNameLoc {
719723

720724
void setNamedTypeLoc(TypeSourceInfo *TInfo) { NamedType.TInfo = TInfo; }
721725

722-
void setCXXOperatorNameRange(SourceRange Range) {
723-
CXXOperatorName.BeginOpNameLoc = Range.getBegin();
724-
CXXOperatorName.EndOpNameLoc = Range.getEnd();
725-
}
726-
727726
void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
728727
CXXLiteralOperatorName.OpNameLoc = Loc;
729728
}
@@ -739,12 +738,16 @@ class DeclarationNameLoc {
739738

740739
/// Return the beginning location of the getCXXOperatorNameRange() range.
741740
SourceLocation getCXXOperatorNameBeginLoc() const {
742-
return CXXOperatorName.BeginOpNameLoc;
741+
if (!CXXOperatorName.OInfo)
742+
return {};
743+
return CXXOperatorName.OInfo->BeginOpNameLoc;
743744
}
744745

745746
/// Return the end location of the getCXXOperatorNameRange() range.
746747
SourceLocation getCXXOperatorNameEndLoc() const {
747-
return CXXOperatorName.EndOpNameLoc;
748+
if (!CXXOperatorName.OInfo)
749+
return {};
750+
return CXXOperatorName.OInfo->EndOpNameLoc;
748751
}
749752

750753
/// Return the range of the operator name (without the operator keyword).
@@ -771,15 +774,10 @@ class DeclarationNameLoc {
771774
}
772775

773776
/// Construct location information for a non-literal C++ operator.
774-
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc,
775-
SourceLocation EndLoc) {
776-
return makeCXXOperatorNameLoc(SourceRange(BeginLoc, EndLoc));
777-
}
778-
779-
/// Construct location information for a non-literal C++ operator.
780-
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceRange Range) {
777+
static DeclarationNameLoc
778+
makeCXXOperatorNameLoc(CXXOperatorSourceInfo *OInfo) {
781779
DeclarationNameLoc DNL;
782-
DNL.setCXXOperatorNameRange(Range);
780+
DNL.CXXOperatorName.OInfo = OInfo;
783781
return DNL;
784782
}
785783

@@ -849,6 +847,13 @@ struct DeclarationNameInfo {
849847
LocInfo = DeclarationNameLoc::makeNamedTypeLoc(TInfo);
850848
}
851849

850+
/// Sets the range of the operator name (without the operator keyword).
851+
/// Assumes it is a C++ operator.
852+
void setCXXOperatorNameInfo(CXXOperatorSourceInfo *OInfo) {
853+
assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
854+
LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(OInfo);
855+
}
856+
852857
/// getCXXOperatorNameRange - Gets the range of the operator name
853858
/// (without the operator keyword). Assumes it is a (non-literal) operator.
854859
SourceRange getCXXOperatorNameRange() const {
@@ -857,13 +862,6 @@ struct DeclarationNameInfo {
857862
return LocInfo.getCXXOperatorNameRange();
858863
}
859864

860-
/// setCXXOperatorNameRange - Sets the range of the operator name
861-
/// (without the operator keyword). Assumes it is a C++ operator.
862-
void setCXXOperatorNameRange(SourceRange R) {
863-
assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
864-
LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(R);
865-
}
866-
867865
/// getCXXLiteralOperatorNameLoc - Returns the location of the literal
868866
/// operator name (not the operator keyword).
869867
/// Assumes it is a literal operator.

0 commit comments

Comments
 (0)