Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ struct CognitiveComplexity final {
// https://sonarcloud.io/projects?languages=c%2Ccpp&size=5 we can estimate:
// value ~20 would result in no allocs for 98% of functions, ~12 for 96%, ~10
// for 91%, ~8 for 88%, ~6 for 84%, ~4 for 77%, ~2 for 64%, and ~1 for 37%.
static_assert(sizeof(Detail) <= 8,
static_assert(sizeof(Detail) <= 16,
"Since we use SmallVector to minimize the amount of "
"allocations, we also need to consider the price we pay for "
"that in terms of stack usage. "
"Thus, it is good to minimize the size of the Detail struct.");
SmallVector<Detail, DefaultLimit> Details; // 25 elements is 200 bytes.
SmallVector<Detail, DefaultLimit> Details; // 25 elements is 400 bytes.
// Yes, 25 is a magic number. This is the seemingly-sane default for the
// upper limit for function cognitive complexity. Thus it would make sense
// to avoid allocations for any function that does not violate the limit.
Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,9 @@ TEST(SourceCodeTests, isSpelledInSource) {
// FIXME: Should it return false on SourceLocation()? Does it matter?
EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM));
EXPECT_FALSE(isSpelledInSource(
SourceLocation::getFromRawEncoding(SourceLocation::UIntTy(1 << 31)), SM));
SourceLocation::getFromRawEncoding(
SourceLocation::UIntTy(1ULL << (SourceLocation::Bits - 1))),
SM));
}

struct IncrementalTestStep {
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
getTrivialTypeSourceInfo(QualType T,
SourceLocation Loc = SourceLocation()) const;

CXXOperatorSourceInfo *getCXXOperatorSourceInfo(SourceRange R) const;

/// Add a deallocation callback that will be invoked when the
/// ASTContext is destroyed.
///
Expand Down
14 changes: 10 additions & 4 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,13 +888,17 @@ struct EvaluatedStmt {
bool HasICEInit : 1;
bool CheckedForICEInit : 1;

bool HasSideEffects : 1;
bool CheckedForSideEffects : 1;

LazyDeclStmtPtr Value;
APValue Evaluated;

EvaluatedStmt()
: WasEvaluated(false), IsEvaluating(false),
HasConstantInitialization(false), HasConstantDestruction(false),
HasICEInit(false), CheckedForICEInit(false) {}
HasICEInit(false), CheckedForICEInit(false), HasSideEffects(false),
CheckedForSideEffects(false) {}
};

/// Represents a variable declaration or definition.
Expand Down Expand Up @@ -1353,9 +1357,11 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
return const_cast<VarDecl *>(this)->getInitializingDeclaration();
}

/// Checks whether this declaration has an initializer with side effects,
/// without triggering deserialization if the initializer is not yet
/// deserialized.
/// Checks whether this declaration has an initializer with side effects.
/// The result is cached. If the result hasn't been computed this can trigger
/// deserialization and constant evaluation. By running this during
/// serialization and serializing the result all clients can safely call this
/// without triggering further deserialization.
bool hasInitWithSideEffects() const;

/// Determine whether this variable's value might be usable in a
Expand Down
10 changes: 3 additions & 7 deletions clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1952,17 +1952,13 @@ class DeclContext {
friend class ObjCContainerDecl;
/// For the bits in DeclContextBitfields
LLVM_PREFERRED_TYPE(DeclContextBitfields)
uint32_t : NumDeclContextBits;
uint64_t : NumDeclContextBits;

// Not a bitfield but this saves space.
// Note that ObjCContainerDeclBitfields is full.
SourceLocation AtStart;
uint64_t AtStart : SourceLocation::Bits;
};

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

/// Stores the bits used by LinkageSpecDecl.
/// If modified NumLinkageSpecDeclBits and the accessor
Expand Down
6 changes: 4 additions & 2 deletions clang/include/clang/AST/DeclObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -1090,10 +1090,12 @@ class ObjCContainerDecl : public NamedDecl, public DeclContext {
/// Note, the superclass's properties are not included in the list.
virtual void collectPropertiesToImplement(PropertyMap &PM) const {}

SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; }
SourceLocation getAtStartLoc() const {
return SourceLocation::getFromRawEncoding(ObjCContainerDeclBits.AtStart);
}

void setAtStartLoc(SourceLocation Loc) {
ObjCContainerDeclBits.AtStart = Loc;
ObjCContainerDeclBits.AtStart = Loc.getRawEncoding();
}

// Marks the end of the container.
Expand Down
52 changes: 25 additions & 27 deletions clang/include/clang/AST/DeclarationName.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,11 @@ class DeclarationNameTable {
DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II);
};

struct CXXOperatorSourceInfo {
SourceLocation BeginOpNameLoc;
SourceLocation EndOpNameLoc;
};

/// DeclarationNameLoc - Additional source/type location info
/// for a declaration name. Needs a DeclarationName in order
/// to be interpreted correctly.
Expand All @@ -698,13 +703,12 @@ class DeclarationNameLoc {

// The location (if any) of the operator keyword is stored elsewhere.
struct CXXOpName {
SourceLocation::UIntTy BeginOpNameLoc;
SourceLocation::UIntTy EndOpNameLoc;
CXXOperatorSourceInfo *OInfo;
};

// The location (if any) of the operator keyword is stored elsewhere.
struct CXXLitOpName {
SourceLocation::UIntTy OpNameLoc;
SourceLocation OpNameLoc;
};

// struct {} CXXUsingDirective;
Expand All @@ -719,13 +723,8 @@ class DeclarationNameLoc {

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

void setCXXOperatorNameRange(SourceRange Range) {
CXXOperatorName.BeginOpNameLoc = Range.getBegin().getRawEncoding();
CXXOperatorName.EndOpNameLoc = Range.getEnd().getRawEncoding();
}

void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
CXXLiteralOperatorName.OpNameLoc = Loc;
}

public:
Expand All @@ -739,12 +738,16 @@ class DeclarationNameLoc {

/// Return the beginning location of the getCXXOperatorNameRange() range.
SourceLocation getCXXOperatorNameBeginLoc() const {
return SourceLocation::getFromRawEncoding(CXXOperatorName.BeginOpNameLoc);
if (!CXXOperatorName.OInfo)
return {};
return CXXOperatorName.OInfo->BeginOpNameLoc;
}

/// Return the end location of the getCXXOperatorNameRange() range.
SourceLocation getCXXOperatorNameEndLoc() const {
return SourceLocation::getFromRawEncoding(CXXOperatorName.EndOpNameLoc);
if (!CXXOperatorName.OInfo)
return {};
return CXXOperatorName.OInfo->EndOpNameLoc;
}

/// Return the range of the operator name (without the operator keyword).
Expand All @@ -759,7 +762,7 @@ class DeclarationNameLoc {
/// keyword). Assumes that the object stores location information of a literal
/// operator.
SourceLocation getCXXLiteralOperatorNameLoc() const {
return SourceLocation::getFromRawEncoding(CXXLiteralOperatorName.OpNameLoc);
return CXXLiteralOperatorName.OpNameLoc;
}

/// Construct location information for a constructor, destructor or conversion
Expand All @@ -771,15 +774,10 @@ class DeclarationNameLoc {
}

/// Construct location information for a non-literal C++ operator.
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc,
SourceLocation EndLoc) {
return makeCXXOperatorNameLoc(SourceRange(BeginLoc, EndLoc));
}

/// Construct location information for a non-literal C++ operator.
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceRange Range) {
static DeclarationNameLoc
makeCXXOperatorNameLoc(CXXOperatorSourceInfo *OInfo) {
DeclarationNameLoc DNL;
DNL.setCXXOperatorNameRange(Range);
DNL.CXXOperatorName.OInfo = OInfo;
return DNL;
}

Expand Down Expand Up @@ -849,6 +847,13 @@ struct DeclarationNameInfo {
LocInfo = DeclarationNameLoc::makeNamedTypeLoc(TInfo);
}

/// Sets the range of the operator name (without the operator keyword).
/// Assumes it is a C++ operator.
void setCXXOperatorNameInfo(CXXOperatorSourceInfo *OInfo) {
assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(OInfo);
}

/// getCXXOperatorNameRange - Gets the range of the operator name
/// (without the operator keyword). Assumes it is a (non-literal) operator.
SourceRange getCXXOperatorNameRange() const {
Expand All @@ -857,13 +862,6 @@ struct DeclarationNameInfo {
return LocInfo.getCXXOperatorNameRange();
}

/// setCXXOperatorNameRange - Sets the range of the operator name
/// (without the operator keyword). Assumes it is a C++ operator.
void setCXXOperatorNameRange(SourceRange R) {
assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(R);
}

/// getCXXLiteralOperatorNameLoc - Returns the location of the literal
/// operator name (not the operator keyword).
/// Assumes it is a literal operator.
Expand Down
Loading