Skip to content

[clang][Modules] Fix the Size of RecordDecl's BitCodeAbbrevOp #133500

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

Merged
merged 1 commit into from
Apr 1, 2025

Conversation

qiongsiwu
Copy link
Contributor

@qiongsiwu qiongsiwu commented Mar 28, 2025

https://github.com/llvm/llvm-project/pull/102040/files#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR2477 added 1 bit to RecordDecl's serialization format, but did not increment its abbreviation size.

This can lead to rare cases where a record may overflow if the RecordDecl's getArgPassingRestrictions() returns something bigger than 1 (see here).

rdar://143763558

Unverified

The signing certificate or its chain could not be verified.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels Mar 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 28, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Qiongsi Wu (qiongsiwu)

Changes

https://github.com/llvm/llvm-project/pull/102040/files#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR2477 added 1 bit to RecordDecl's serialization format, but did not increment its abbreviation size.

This can lead to rare cases where a record may overflow if a RecordDecl's getArgPassingRestrictions() returns something bigger than 1 (see here).


Full diff: https://github.com/llvm/llvm-project/pull/133500.diff

1 Files Affected:

  • (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+1-1)
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index a14b8cf201bba..f377c145a4204 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2579,7 +2579,7 @@ void ASTWriter::WriteDeclAbbrevs() {
   // RecordDecl
   Abv->Add(BitCodeAbbrevOp(
       BitCodeAbbrevOp::Fixed,
-      13)); // Packed Record Decl Bits: FlexibleArrayMember,
+      14)); // Packed Record Decl Bits: FlexibleArrayMember,
             // AnonymousStructUnion, hasObjectMember, hasVolatileMember,
             // isNonTrivialToPrimitiveDefaultInitialize,
             // isNonTrivialToPrimitiveCopy, isNonTrivialToPrimitiveDestroy,

@qiongsiwu
Copy link
Contributor Author

qiongsiwu commented Mar 28, 2025

Note to reviewers:

A test case is added by swiftlang#10371. This is difficult to test in the community llvm code base because the failure was discovered when building structs with __ptrauth, which is not available here. I tried a few things to simulate the situation but found it difficult. I am all ears if there are better ways to test this.

More generally, should we hardcode the size in BitCodeAbbrevOp at all? It feels that some mistakes are bound to happen when things go out of sync. My intuition is that it might be a major surgery to refactor this code but I have not looked into it in detail.

Copy link
Contributor

@higher-performance higher-performance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for spotting & fixing this! Approving, but I'm also quite unfamiliar with these so please wait for another approval.

Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@qiongsiwu qiongsiwu merged commit 4a73c99 into llvm:main Apr 1, 2025
14 checks passed
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request Apr 2, 2025
…vm#133500)

https://github.com/llvm/llvm-project/pull/102040/files#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR2477
added 1 bit to `RecordDecl`'s serialization format, but did not
increment its abbreviation size.

This can lead to rare cases where a record may overflow if the
`RecordDecl`'s `getArgPassingRestrictions()` returns something bigger
than 1 (see
[here](https://github.com/llvm/llvm-project/blob/b3f01a6aa45b00240cec1c64286b85d7ba87e2af/clang/lib/Serialization/ASTWriterDecl.cpp#L688)).

rdar://143763558
curmudg-eon pushed a commit to curmudg-eon/llvm-project that referenced this pull request Apr 18, 2025
…vm#133500)

https://github.com/llvm/llvm-project/pull/102040/files#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR2477
added 1 bit to `RecordDecl`'s serialization format, but did not
increment its abbreviation size.

This can lead to rare cases where a record may overflow if the
`RecordDecl`'s `getArgPassingRestrictions()` returns something bigger
than 1 (see
[here](https://github.com/llvm/llvm-project/blob/b3f01a6aa45b00240cec1c64286b85d7ba87e2af/clang/lib/Serialization/ASTWriterDecl.cpp#L688)).

rdar://143763558
(cherry picked from commit 4a73c99)
qiongsiwu added a commit to swiftlang/llvm-project that referenced this pull request Apr 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…10513

This is a test case for llvm#133500.

This test case cannot be added to upstream llvm because upstream currently does not have the __ptrauth qualifier yet. llvm#100830 will add the qualifier, and we shall consider upstreaming this test case when llvm#100830 lands.

rdar://143763558

(cherry picked from commit 3af0d75)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants