This is an archive of the discontinued LLVM Phabricator instance.

[clang][modules] Use relative offsets for input files
ClosedPublic

Authored by jansvoboda11 on Aug 22 2023, 6:36 PM.

Details

Summary

This patch replaces absolute offsets into the input files block with offsets relative to the block start. This makes the whole section "relocatable". I confirmed all other uses of GetCurrentBitNo() are turned into relative offsets before being serialized into the AST file.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Aug 22 2023, 6:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2023, 6:36 PM
Herald added a subscriber: ributzka. · View Herald Transcript
jansvoboda11 requested review of this revision.Aug 22 2023, 6:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2023, 6:36 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
benlangmuir added inline comments.Aug 23 2023, 9:59 AM
clang/include/clang/Serialization/ModuleFile.h
249

Doesn't InputFilesCursor already know where the input files block starts?

clang/lib/Serialization/ASTReader.cpp
5334

We should initialize this to something - either 0 or maybe ~0 so it will be invalid?

jansvoboda11 added inline comments.Aug 23 2023, 12:30 PM
clang/include/clang/Serialization/ModuleFile.h
249

I think it does. We should be able to remove this and always call InputFilesCursor::GetCurrentBitNo() at the start. I implemented it this way because it's consistent with the existing pattern: SLocEntryCursor/SourceManagerBlockStartOffset, MacroCursor/MacroOffsetsBase, DeclsCursor/DeclsBlockStartOffset.

LMK if you feel strongly about it and I can look into getting rid of the extra offset base members.

clang/lib/Serialization/ASTReader.cpp
5334

Good point, I'll do that along with initializing the member variable.

benlangmuir added inline comments.Aug 23 2023, 1:01 PM
clang/include/clang/Serialization/ModuleFile.h
249

Since it's consistent with other uses I'm fine with keeping it as-is for this patch. Would be nice to clean them all up in a follow up, but not required.

Initialize absolute offsets in ASTReader/ModuleFile.

jansvoboda11 marked 3 inline comments as done.Aug 23 2023, 2:50 PM
benlangmuir accepted this revision.Aug 23 2023, 2:55 PM
This revision is now accepted and ready to land.Aug 23 2023, 2:55 PM
This revision was landed with ongoing or failed builds.Aug 24 2023, 9:16 AM
This revision was automatically updated to reflect the committed changes.
phosek added a subscriber: phosek.Aug 24 2023, 2:22 PM

After this change, all libc++ clang_modules_include.gen.py tests started failing on our Linux builders:

Script:
--
: 'COMPILED WITH';  /b/s/w/ir/x/w/llvm_build/./bin/clang++ /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/test/libcxx/clang_modules_include.gen.py/algorithm.compile.pass.cpp -pthread --target=aarch64-unknown-linux-gnu -nostdinc++ -I /b/s/w/ir/x/w/llvm_build/include/c++/v1 -I /b/s/w/ir/x/w/llvm_build/include/aarch64-unknown-linux-gnu/c++/v1 -I /b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -Werror=thread-safety -Wuser-defined-warnings  -fsyntax-only
: 'RUN: at line 2';   /b/s/w/ir/x/w/llvm_build/./bin/clang++ /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/test/libcxx/clang_modules_include.gen.py/algorithm.compile.pass.cpp -pthread --target=aarch64-unknown-linux-gnu -nostdinc++ -I /b/s/w/ir/x/w/llvm_build/include/c++/v1 -I /b/s/w/ir/x/w/llvm_build/include/aarch64-unknown-linux-gnu/c++/v1 -I /b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -Werror=thread-safety -Wuser-defined-warnings  -fmodules -fcxx-modules -fmodules-cache-path=/b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/test/libcxx/clang_modules_include.gen.py/Output/algorithm.compile.pass.cpp.dir/t.tmp -fsyntax-only
--
Exit Code: 1

Command Output (stdout):
--
$ ":" "COMPILED WITH"
$ "/b/s/w/ir/x/w/llvm_build/./bin/clang++" "/b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/test/libcxx/clang_modules_include.gen.py/algorithm.compile.pass.cpp" "-pthread" "--target=aarch64-unknown-linux-gnu" "-nostdinc++" "-I" "/b/s/w/ir/x/w/llvm_build/include/c++/v1" "-I" "/b/s/w/ir/x/w/llvm_build/include/aarch64-unknown-linux-gnu/c++/v1" "-I" "/b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support" "-std=c++26" "-Werror" "-Wall" "-Wctad-maybe-unsupported" "-Wextra" "-Wshadow" "-Wundef" "-Wunused-template" "-Wno-unused-command-line-argument" "-Wno-attributes" "-Wno-pessimizing-move" "-Wno-noexcept-type" "-Wno-atomic-alignment" "-Wno-reserved-module-identifier" "-Wno-user-defined-literals" "-Wno-tautological-compare" "-Wsign-compare" "-Wunused-variable" "-Wunused-parameter" "-Wunreachable-code" "-Wno-unused-local-typedef" "-Wno-local-type-template-args" "-Wno-c++11-extensions" "-Wno-unknown-pragmas" "-Wno-pass-failed" "-Wno-mismatched-new-delete" "-Wno-redundant-move" "-Wno-self-move" "-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER" "-D_LIBCPP_ENABLE_EXPERIMENTAL" "-Werror=thread-safety" "-Wuser-defined-warnings" "-fsyntax-only"
$ ":" "RUN: at line 2"
$ "/b/s/w/ir/x/w/llvm_build/./bin/clang++" "/b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/test/libcxx/clang_modules_include.gen.py/algorithm.compile.pass.cpp" "-pthread" "--target=aarch64-unknown-linux-gnu" "-nostdinc++" "-I" "/b/s/w/ir/x/w/llvm_build/include/c++/v1" "-I" "/b/s/w/ir/x/w/llvm_build/include/aarch64-unknown-linux-gnu/c++/v1" "-I" "/b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support" "-std=c++26" "-Werror" "-Wall" "-Wctad-maybe-unsupported" "-Wextra" "-Wshadow" "-Wundef" "-Wunused-template" "-Wno-unused-command-line-argument" "-Wno-attributes" "-Wno-pessimizing-move" "-Wno-noexcept-type" "-Wno-atomic-alignment" "-Wno-reserved-module-identifier" "-Wno-user-defined-literals" "-Wno-tautological-compare" "-Wsign-compare" "-Wunused-variable" "-Wunused-parameter" "-Wunreachable-code" "-Wno-unused-local-typedef" "-Wno-local-type-template-args" "-Wno-c++11-extensions" "-Wno-unknown-pragmas" "-Wno-pass-failed" "-Wno-mismatched-new-delete" "-Wno-redundant-move" "-Wno-self-move" "-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER" "-D_LIBCPP_ENABLE_EXPERIMENTAL" "-Werror=thread-safety" "-Wuser-defined-warnings" "-fmodules" "-fcxx-modules" "-fmodules-cache-path=/b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/test/libcxx/clang_modules_include.gen.py/Output/algorithm.compile.pass.cpp.dir/t.tmp" "-fsyntax-only"
# command stderr:
clang++: clang/lib/Serialization/ASTReader.cpp:6515: void clang::ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &): Assertion `IDAndOffset.second == 0 && "not a start location for a FileID"' failed.
While building module 'std_algorithm' imported from /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/test/libcxx/clang_modules_include.gen.py/algorithm.compile.pass.cpp:22:
While building module 'std_private_algorithm_adjacent_find' imported from /b/s/w/ir/x/w/llvm_build/include/c++/v1/algorithm:1744:
While building module 'std_private_algorithm_iterator_operations' imported from /b/s/w/ir/x/w/llvm_build/include/c++/v1/__algorithm/adjacent_find.h:14:
While building module 'std_private_algorithm_ranges_iterator_concept' imported from /b/s/w/ir/x/w/llvm_build/include/c++/v1/__algorithm/iterator_operations.h:13:
In file included from <module-includes>:1:
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__algorithm/ranges_iterator_concept.h:13:10: fatal error: could not build module 'std_private_iterator_concepts'
   13 | #include <__iterator/concepts.h>
      |  ~~~~~~~~^
...

You can see the full output at https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-arm64/b8771862804321535569/test-results. Would it be possible to revert this change?

After this change, all libc++ clang_modules_include.gen.py tests started failing on our Linux builders:

...

You can see the full output at https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-arm64/b8771862804321535569/test-results. Would it be possible to revert this change?

Thanks for notifying me. Reverting now...

@phosek BTW can you confirm whether these started failing with this patch or with D158573?

@phosek BTW can you confirm whether these started failing with this patch or with D158573?

I'm trying to do a local build now to find out.

@phosek BTW can you confirm whether these started failing with this patch or with D158573?

I'm trying to do a local build now to find out.

Looks like it was D158573 so it should be safe to reland this, sorry about the confusion.