This is an archive of the discontinued LLVM Phabricator instance.

[Clang][MS] Remove assertion on BaseOffset can't be smaller than Size.
ClosedPublic

Authored by zequanwu on Jun 8 2023, 2:43 PM.

Details

Summary

This assertion triggered when we have two base classes sharing the same offset
and the first base is empty and the second class is non-empty.
Remove it for correctness.

I can't add a test case for this because -foverride-record-layout doesn't read
base class info at all. I can add that support later for testing if needed.

Diff Detail

Event Timeline

zequanwu created this revision.Jun 8 2023, 2:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2023, 2:43 PM
zequanwu requested review of this revision.Jun 8 2023, 2:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2023, 2:43 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rnk added a comment.Jun 8 2023, 2:53 PM

Please do extend the simple record layout dumping format. I think it should be relatively simple to add string dumping and parsing to clang/lib/Frontend/LayoutOverrideSource.cpp.

zequanwu updated this revision to Diff 529757.Jun 8 2023, 3:52 PM

Extend the output and reading of -fdump-record-layouts-simple.
Add a test case.

rnk added inline comments.Jun 14 2023, 10:18 AM
clang/lib/AST/RecordLayoutBuilder.cpp
3727

Rather than iterating the map and sorting afterwards, IMO it's better to iterate RD->bases() and look each base up in the map and use that offset. It guarantees they'll be in the right order, even if the offsets aren't in ascending order (although due to the ABI, they usually are).

3739

Ditto here, better to iterate over vbases().

clang/lib/Frontend/LayoutOverrideSource.cpp
38

Can you pass in ULL directly here, rather than making a local and copying it out?

228

I think it's better to iterate vbases() directly, and then iterate bases() and skip bases that are virtual.

clang/test/CodeGenCXX/override-layout-ms.cpp
2

Go ahead and add a second RUN line without the "override-record-layout" flag to confirm the layout is correct.

zequanwu updated this revision to Diff 531438.Jun 14 2023, 11:28 AM
zequanwu marked 5 inline comments as done.

Address comments.

rnk accepted this revision.Jun 14 2023, 12:52 PM

lgtm, thanks!

This revision is now accepted and ready to land.Jun 14 2023, 12:52 PM
This revision was landed with ongoing or failed builds.Jun 14 2023, 1:48 PM
This revision was automatically updated to reflect the committed changes.

Hi. I think this caused the override-layout.cpp test to fail on our windows builder (https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8778279637538184401/+/u/clang/test/stdout?format=raw):

FAIL: Clang :: CodeGenCXX/override-layout.cpp (7816 of 18732)
******************** TEST 'Clang :: CodeGenCXX/override-layout.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 -internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include -nostdsysteminc -std=c++14 -w -fdump-record-layouts-simple C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts
: 'RUN: at line 2';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 -internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include -nostdsysteminc -std=c++14 -w -fdump-record-layouts-simple C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before
: 'RUN: at line 3';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 -internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include -nostdsysteminc -std=c++14 -w -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
: 'RUN: at line 4';   diff -u C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
: 'RUN: at line 5';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\filecheck.exe --check-prefixes=CHECK,PRE17 C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp < C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
: 'RUN: at line 7';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 -internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include -nostdsysteminc -std=c++17 -w -fdump-record-layouts-simple C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts
: 'RUN: at line 8';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 -internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include -nostdsysteminc -std=c++17 -w -fdump-record-layouts-simple C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before
: 'RUN: at line 9';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe -cc1 -internal-isystem c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include -nostdsysteminc -std=c++17 -w -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp > C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
: 'RUN: at line 10';   diff -u C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
: 'RUN: at line 11';   c:\b\s\w\ir\x\w\staging\llvm_build\bin\filecheck.exe --check-prefixes=CHECK,CXX17 C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp < C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
--
Exit Code: 1

Command Output (stdout):
--
$ ":" "RUN: at line 1"
$ "c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe" "-cc1" "-internal-isystem" "c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include" "-nostdsysteminc" "-std=c++14" "-w" "-fdump-record-layouts-simple" "C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp"
$ ":" "RUN: at line 2"
$ "c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe" "-cc1" "-internal-isystem" "c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include" "-nostdsysteminc" "-std=c++14" "-w" "-fdump-record-layouts-simple" "C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp"
$ ":" "RUN: at line 3"
$ "c:\b\s\w\ir\x\w\staging\llvm_build\bin\clang.exe" "-cc1" "-internal-isystem" "c:\b\s\w\ir\x\w\staging\llvm_build\lib\clang\17\include" "-nostdsysteminc" "-std=c++14" "-w" "-DPACKED=" "-DALIGNED16=" "-fdump-record-layouts-simple" "-foverride-record-layout=C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.layouts" "C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\CodeGenCXX\override-layout.cpp"
$ ":" "RUN: at line 4"
$ "diff" "-u" "C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before" "C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after"
# command output:
--- C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.before
+++ C:\b\s\w\ir\x\w\staging\llvm_build\tools\clang\test\CodeGenCXX\Output\override-layout.cpp.tmp.after
@@ -116,5 +116,5 @@
   Size:512
   Alignment:128
   BaseOffsets: [0]>
-  VBaseOffsets: [48]>
+  VBaseOffsets: [33]>
   FieldOffsets: [256]>

error: command failed with exit status: 1

--

Would you be able to send out a fix or revert? Thanks.

This is still breaking check-clang on windows: http://45.33.8.238/win/79908/step_7.txt

Please take a look and revert for now if it takes a while to fix.

This is still breaking check-clang on windows: http://45.33.8.238/win/79908/step_7.txt

Please take a look and revert for now if it takes a while to fix.

Sorry, I thought I applied the fix, but that was on another machine. The actually fix is in https://reviews.llvm.org/rG9d910b1073198716f85e5a7e7e9c8fd1f24d4c60.