This is an archive of the discontinued LLVM Phabricator instance.

[tbaa] Handle base classes in struct tbaa
ClosedPublic

Authored by brunodf on Jun 3 2022, 4:10 AM.

Details

Summary

This is a fix for the miscompilation reported in https://github.com/llvm/llvm-project/issues/55384

Not adding a new test case since existing test cases already cover base classes (including new-struct-path tbaa).

Diff Detail

Event Timeline

brunodf created this revision.Jun 3 2022, 4:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 3 2022, 4:10 AM
Herald added a subscriber: kosarev. · View Herald Transcript
brunodf requested review of this revision.Jun 3 2022, 4:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 3 2022, 4:10 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Jun 15 2022, 2:08 AM
This revision was automatically updated to reflect the committed changes.
fhahn added a subscriber: fhahn.Jun 23 2022, 6:40 AM

It looks like this commit is breaking bootstrap builds of LLVM/Clang, e.g. https://lab.llvm.org/buildbot/#/builders/37/builds/14224

FAILED: lib/Bitcode/Reader/CMakeFiles/LLVMBitReader.dir/BitcodeReader.cpp.o 
/b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/bin/clang++  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Bitcode/Reader -I/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/Bitcode/Reader -Iinclude -I/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG    -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT lib/Bitcode/Reader/CMakeFiles/LLVMBitReader.dir/BitcodeRea
 der.cpp.o -MF lib/Bitcode/Reader/CMakeFiles/LLVMBitReader.dir/BitcodeReader.cpp.o.d -o lib/Bitcode/Reader/CMakeFiles/LLVMBitReader.dir/BitcodeReader.cpp.o -c /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Offsets must be increasing!
  %45 = load ptr, ptr %Context.i1113, align 8, !dbg !137343, !tbaa !97945, !noalias !137026
!68773 = !{!"_ZTSN12_GLOBAL__N_113BitcodeReaderE", !68334, i64 8, !68774, i64 0, !61585, i64 432, !61585, i64 440, !61620, i64 448, !61620, i64 456, !62256, i64 464, !61620, i64 472, !68775, i64 480, !68775, i64 504, !68778, i64 528, !68781, i64 552, !68783, i64 584, !68785, i64 616, !68561, i64 648, !68787, i64 712, !68788, i64 728, !68791, i64 752, !68795, i64 784, !68800, i64 1312, !68803, i64 1336, !68806, i64 1360, !68809, i64 1384, !68812, i64 1408, !68817, i64 1456, !68820, i64 1480, !68823, i64 1504, !68823, i64 1536, !62256, i64 1568, !68825, i64 1576, !68827, i64 1608, !68830, i64 1632, !68832, i64 1664, !68820, i64 1744, !62256, i64 1768, !62256, i64 1769, !62256, i64 1770, !68836, i64 1776, !68775, i64 1848, !68841, i64 1872, !68847, i64 1904}
clang++: /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10631: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `!verifyFunction(*L->getHeader()->getParent(), &dbgs())' failed.

Please take a look and revert the patch if the fix isn't trivial.

Please take a look and revert the patch if the fix isn't trivial.

the patch has already been reverted so Bruno can investigate.

brunodf updated this revision to Diff 441017.Jun 29 2022, 8:03 AM

New version that fixes the problem with base classes not appearing in order of increasing offset.

This issue was discovered in the multistage build, but the test case has now been extended for this situation.

Also changed to obtain the the size of the base subobject with getDataSize() since other subobjects may be allocated in its tail padding.

brunodf reopened this revision.Jun 29 2022, 8:05 AM
This revision is now accepted and ready to land.Jun 29 2022, 8:05 AM
brunodf requested review of this revision.Jun 29 2022, 8:06 AM
efriedma added inline comments.
clang/lib/CodeGen/CodeGenTBAA.cpp
366

Maybe add a comment explaining why each TBAAStructField has a unique offset. (If the offsets aren't unique, you need to use stable_sort.)

brunodf updated this revision to Diff 441294.Jun 30 2022, 1:06 AM

Adding comment regarding empty subobjects.

brunodf marked an inline comment as done.Jun 30 2022, 1:08 AM
This revision is now accepted and ready to land.Jul 6 2022, 5:35 AM
This revision was automatically updated to reflect the committed changes.