Skip to content
This repository was archived by the owner on Jun 9, 2026. It is now read-only.

Commit 8f34656

Browse files
maleadtclaude
andcommitted
Emit named structs as STRUCT_NAMED instead of OPAQUE.
Named (non-literal) structs were always written with the OPAQUE record code while still carrying their body operands. LLVM 5/7 require an OPAQUE record to have no body and reject it with "Invalid record", so any module with a named struct failed to round-trip. Use STRUCT_NAMED for structs with a body and reserve OPAQUE for genuinely opaque ones. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit 3694275)
1 parent 9f2c2e7 commit 8f34656

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

llvm/lib/Bitcode/LegacyWriter/BitcodeWriter50.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,10 @@ void ModuleBitcodeWriter50::writeTypeTable() {
908908
Code = bitc::TYPE_CODE_STRUCT_ANON;
909909
AbbrevToUse = StructAnonAbbrev;
910910
} else {
911-
Code = bitc::TYPE_CODE_OPAQUE;
911+
// A named struct with a body must use STRUCT_NAMED; OPAQUE is only for
912+
// bodyless structs (LLVM 5/7 reject an OPAQUE record carrying a body).
913+
Code = ST->isOpaque() ? bitc::TYPE_CODE_OPAQUE
914+
: bitc::TYPE_CODE_STRUCT_NAMED;
912915

913916
// Emit the name if it is present.
914917
if (!ST->getName().empty())

llvm/lib/Bitcode/LegacyWriter/BitcodeWriter70.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,10 @@ void ModuleBitcodeWriter70::writeTypeTable() {
925925
Code = bitc::TYPE_CODE_STRUCT_ANON;
926926
AbbrevToUse = StructAnonAbbrev;
927927
} else {
928-
Code = bitc::TYPE_CODE_OPAQUE;
928+
// A named struct with a body must use STRUCT_NAMED; OPAQUE is only for
929+
// bodyless structs (LLVM 5/7 reject an OPAQUE record carrying a body).
930+
Code = ST->isOpaque() ? bitc::TYPE_CODE_OPAQUE
931+
: bitc::TYPE_CODE_STRUCT_NAMED;
929932

930933
// Emit the name if it is present.
931934
if (!ST->getName().empty())

0 commit comments

Comments
 (0)