[clang] [llvm] [Modules] No transitive source location change (PR #86912)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 27 22:56:57 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff c6a65e4b0c80245d766ae2f2f7305b5371d096f5 9046d2156cb8641cccf76c643b6f88994105f452 -- clang/test/Modules/no-transitive-source-location-change.cppm clang/include/clang/Basic/SourceLocation.h clang/include/clang/Serialization/ASTBitCodes.h clang/include/clang/Serialization/ASTReader.h clang/include/clang/Serialization/ASTWriter.h clang/include/clang/Serialization/ModuleFile.h clang/include/clang/Serialization/SourceLocationEncoding.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTReaderDecl.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/lib/Serialization/ModuleFile.cpp clang/test/Modules/pr61067.cppm clang/unittests/Serialization/SourceLocationEncodingTest.cpp llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h
index 8ccf098d4e..628ce03572 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -188,15 +188,10 @@ struct PPEntityOffset {
uint32_t BitOffset;
PPEntityOffset(RawLocEncoding Begin, RawLocEncoding End, uint32_t BitOffset)
- : Begin(Begin), End(End),
- BitOffset(BitOffset) {}
+ : Begin(Begin), End(End), BitOffset(BitOffset) {}
- RawLocEncoding getBegin() const {
- return Begin;
- }
- RawLocEncoding getEnd() const {
- return End;
- }
+ RawLocEncoding getBegin() const { return Begin; }
+ RawLocEncoding getEnd() const { return End; }
};
/// Source range of a skipped preprocessor region
@@ -209,15 +204,10 @@ struct PPSkippedRange {
RawLocEncoding End;
PPSkippedRange(RawLocEncoding Begin, RawLocEncoding End)
- : Begin(Begin), End(End) {
- }
+ : Begin(Begin), End(End) {}
- RawLocEncoding getBegin() const {
- return Begin;
- }
- RawLocEncoding getEnd() const {
- return End;
- }
+ RawLocEncoding getBegin() const { return Begin; }
+ RawLocEncoding getEnd() const { return End; }
};
/// Offset in the AST file. Use splitted 64-bit integer into low/high
@@ -255,17 +245,14 @@ struct DeclOffset {
DeclOffset() = default;
DeclOffset(RawLocEncoding RawLoc, uint64_t BitOffset,
- uint64_t DeclTypesBlockStartOffset) : RawLoc(RawLoc) {
+ uint64_t DeclTypesBlockStartOffset)
+ : RawLoc(RawLoc) {
setBitOffset(BitOffset, DeclTypesBlockStartOffset);
}
- void setRawLoc(RawLocEncoding Loc) {
- RawLoc = Loc;
- }
+ void setRawLoc(RawLocEncoding Loc) { RawLoc = Loc; }
- RawLocEncoding getRawLoc() const {
- return RawLoc;
- }
+ RawLocEncoding getRawLoc() const { return RawLoc; }
void setBitOffset(uint64_t Offset, const uint64_t DeclTypesBlockStartOffset) {
BitOffset.setBitOffset(Offset - DeclTypesBlockStartOffset);
diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h
index 44d6b3b8e1..017c6b76a9 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -942,9 +942,11 @@ private:
/// Sema tracks these to emit deferred diags.
llvm::SmallSetVector<serialization::DeclID, 4> DeclsToCheckForDeferredDiags;
- /// The module files imported by different module files. Indirectly imported module
- /// files are included too. The information comes from ReadModuleOffsetMap(ModuleFile&).
- mutable llvm::DenseMap<ModuleFile *, llvm::SmallVector<ModuleFile *>> ImportedModuleFiles;
+ /// The module files imported by different module files. Indirectly imported
+ /// module files are included too. The information comes from
+ /// ReadModuleOffsetMap(ModuleFile&).
+ mutable llvm::DenseMap<ModuleFile *, llvm::SmallVector<ModuleFile *>>
+ ImportedModuleFiles;
private:
struct ImportedSubmodule {
@@ -2175,8 +2177,8 @@ public:
/// Retrieve the global submodule ID given a module and its local ID
/// number.
- serialization::SubmoduleID
- getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) const;
+ serialization::SubmoduleID getGlobalSubmoduleID(ModuleFile &M,
+ unsigned LocalID) const;
/// Retrieve the submodule that corresponds to a global submodule ID.
///
@@ -2236,14 +2238,14 @@ public:
}
/// Read a source location from raw form.
- SourceLocation ReadRawSourceLocation(ModuleFile &MF,
- RawLocEncoding Raw,
- LocSeq *Seq = nullptr) const {
+ SourceLocation ReadRawSourceLocation(ModuleFile &MF, RawLocEncoding Raw,
+ LocSeq *Seq = nullptr) const {
if (!MF.ModuleOffsetMap.empty())
- ReadModuleOffsetMap(MF);
+ ReadModuleOffsetMap(MF);
auto [Loc, ModuleFileIndex] = ReadUntranslatedSourceLocation(Raw, Seq);
- ModuleFile *ModuleFileHomingLoc = ModuleFileIndex ? ImportedModuleFiles[&MF][ModuleFileIndex - 1] : &MF;
+ ModuleFile *ModuleFileHomingLoc =
+ ModuleFileIndex ? ImportedModuleFiles[&MF][ModuleFileIndex - 1] : &MF;
return TranslateSourceLocation(*ModuleFileHomingLoc, Loc);
}
diff --git a/clang/include/clang/Serialization/SourceLocationEncoding.h b/clang/include/clang/Serialization/SourceLocationEncoding.h
index 6e56d20667..9e0f39cd3f 100644
--- a/clang/include/clang/Serialization/SourceLocationEncoding.h
+++ b/clang/include/clang/Serialization/SourceLocationEncoding.h
@@ -54,16 +54,17 @@ class SourceLocationEncoding {
public:
using RawLocEncoding = uint64_t;
- static RawLocEncoding encode(SourceLocation Loc,
- UIntTy BaseOffset,
- unsigned BaseModuleFileIndex,
- SourceLocationSequence * = nullptr);
- static std::pair<SourceLocation, unsigned> decode(RawLocEncoding, SourceLocationSequence * = nullptr);
+ static RawLocEncoding encode(SourceLocation Loc, UIntTy BaseOffset,
+ unsigned BaseModuleFileIndex,
+ SourceLocationSequence * = nullptr);
+ static std::pair<SourceLocation, unsigned>
+ decode(RawLocEncoding, SourceLocationSequence * = nullptr);
};
/// TODO: Remove SourceLocationSequence since it is not used now.
/// Since we will put the index for ModuleFile in the high bits in the encodings
-/// for source locations, it is meaningless to reduce the size of source locations.
+/// for source locations, it is meaningless to reduce the size of source
+/// locations.
///
/// Serialized encoding of a sequence of SourceLocations.
///
@@ -158,10 +159,9 @@ public:
};
inline SourceLocationEncoding::RawLocEncoding
-SourceLocationEncoding::encode(SourceLocation Loc,
- UIntTy BaseOffset,
- unsigned BaseModuleFileIndex,
- SourceLocationSequence *Seq) {
+SourceLocationEncoding::encode(SourceLocation Loc, UIntTy BaseOffset,
+ unsigned BaseModuleFileIndex,
+ SourceLocationSequence *Seq) {
if (Loc.isInvalid())
return 0;
@@ -175,7 +175,8 @@ SourceLocationEncoding::encode(SourceLocation Loc,
return Encoded;
}
inline std::pair<SourceLocation, unsigned>
-SourceLocationEncoding::decode(RawLocEncoding Encoded, SourceLocationSequence *Seq) {
+SourceLocationEncoding::decode(RawLocEncoding Encoded,
+ SourceLocationSequence *Seq) {
unsigned ModuleFileIndex = Encoded >> 32;
Encoded &= ((RawLocEncoding)1 << 33) - 1;
SourceLocation Loc = SourceLocation::getFromRawEncoding(decodeRaw(Encoded));
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index a7401c02b2..38dcbe2177 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3038,7 +3038,8 @@ ASTReader::ReadControlBlock(ModuleFile &F,
// The import location will be the local one for now; we will adjust
// all import locations of module imports after the global source
// location info are setup, in ReadAST.
- auto [ImportLoc, ImportModuleFileIndex] = ReadUntranslatedSourceLocation(Record[Idx++]);
+ auto [ImportLoc, ImportModuleFileIndex] =
+ ReadUntranslatedSourceLocation(Record[Idx++]);
// The import location must belongs the current module file itself.
assert(ImportModuleFileIndex == 0);
off_t StoredSize = !IsImportingStdCXXModule ? (off_t)Record[Idx++] : 0;
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index ed79dad420..da2c269f5d 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2660,8 +2660,7 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec,
SourceRange R = getAdjustedRange((*E)->getSourceRange());
PreprocessedEntityOffsets.emplace_back(
getRawSourceLocationEncoding(R.getBegin()),
- getRawSourceLocationEncoding(R.getEnd()),
- Offset);
+ getRawSourceLocationEncoding(R.getEnd()), Offset);
if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) {
// Record this macro definition's ID.
@@ -2728,8 +2727,9 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec,
std::vector<PPSkippedRange> SerializedSkippedRanges;
SerializedSkippedRanges.reserve(SkippedRanges.size());
for (auto const& Range : SkippedRanges)
- SerializedSkippedRanges.emplace_back(getRawSourceLocationEncoding(Range.getBegin()),
- getRawSourceLocationEncoding(Range.getEnd()));
+ SerializedSkippedRanges.emplace_back(
+ getRawSourceLocationEncoding(Range.getBegin()),
+ getRawSourceLocationEncoding(Range.getEnd()));
using namespace llvm;
auto Abbrev = std::make_shared<BitCodeAbbrev>();
@@ -2895,8 +2895,9 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
ParentID = SubmoduleIDs[Mod->Parent];
}
- uint64_t DefinitionLoc =
- SourceLocationEncoding::encode(getAdjustedLocation(Mod->DefinitionLoc), /*BaseOffset*/0, /*BaseModuleFileIndex*/0);
+ uint64_t DefinitionLoc = SourceLocationEncoding::encode(
+ getAdjustedLocation(Mod->DefinitionLoc), /*BaseOffset*/ 0,
+ /*BaseModuleFileIndex*/ 0);
// Emit the definition of the block.
{
@@ -5564,10 +5565,11 @@ ASTWriter::getRawSourceLocationEncoding(SourceLocation Loc, LocSeq *Seq) {
unsigned BaseOffset = 0;
unsigned ModuleFileIndex = 0;
- if (Context->getSourceManager().isLoadedSourceLocation(Loc) && Loc.isValid()) {
+ if (Context->getSourceManager().isLoadedSourceLocation(Loc) &&
+ Loc.isValid()) {
assert(getChain());
- auto SLocMapI =
- getChain()->GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - Loc.getOffset() - 1);
+ auto SLocMapI = getChain()->GlobalSLocOffsetMap.find(
+ SourceManager::MaxLoadedOffset - Loc.getOffset() - 1);
assert(SLocMapI != getChain()->GlobalSLocOffsetMap.end() &&
"Corrupted global sloc offset map");
ModuleFile *F = SLocMapI->second;
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index af3e09e69a..b113c433c4 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2777,12 +2777,12 @@ void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
// Record the offset for this declaration
SourceLocation Loc = D->getLocation();
- SourceLocationEncoding::RawLocEncoding RawLoc = getRawSourceLocationEncoding(getAdjustedLocation(Loc));
+ SourceLocationEncoding::RawLocEncoding RawLoc =
+ getRawSourceLocationEncoding(getAdjustedLocation(Loc));
unsigned Index = ID - FirstDeclID;
if (DeclOffsets.size() == Index)
- DeclOffsets.emplace_back(RawLoc, Offset,
- DeclTypesBlockStartOffset);
+ DeclOffsets.emplace_back(RawLoc, Offset, DeclTypesBlockStartOffset);
else if (DeclOffsets.size() < Index) {
// FIXME: Can/should this happen?
DeclOffsets.resize(Index+1);
``````````
</details>
https://github.com/llvm/llvm-project/pull/86912
More information about the llvm-commits
mailing list