Skip to content
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

assertion failures when Type.cpp is compiled with -Os #12024

Closed
llvmbot opened this issue Dec 27, 2011 · 10 comments
Closed

assertion failures when Type.cpp is compiled with -Os #12024

llvmbot opened this issue Dec 27, 2011 · 10 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 27, 2011

Bugzilla Link 11652
Resolution FIXED
Resolved on Jan 05, 2012 05:33
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @asl,@efriedma-quic,@kaomoneus

Extended Description

This is probably a GCC bug, but does anyone have advice on how to reduce it further?

GCC version:
g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2

With r147274 and configuring with these options:

cmake ../llvm -DCMAKE_BUILD_TYPE=Debug -DLLVM_BUILD_CLANG=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_FLAGS=-Os

It causes assertion failures in a ton of unit tests:

.../include/llvm/Type.h:296: llvm::Type* llvm::Type::getContainedType(unsigned int) const: Assertion `i < NumContainedTys && "Index out of range!"' failed.
Stack dump:
0. Running pass 'X86 DAG->DAG Instruction Selection' on function '@foo1'

.../lib/Bitcode/Writer/ValueEnumerator.h:94: unsigned int llvm::ValueEnumerator::getTypeID(llvm::Type*) const: Assertion `I != TypeMap.end() && "Type not in ValueEnumerator!"' failed.
Stack dump:
0. Program arguments: bin/./opt -strip-debug

  1. Running pass 'Bitcode Writer' on module ''.

.../lib/Bitcode/Reader/BitcodeReader.cpp:740: bool llvm::BitcodeReader::ParseTypeTableBody(): Assertion `TypeList[NumRecords] == 0 && "Already read type?"' failed.

Expected Passes : 4167
Expected Failures : 50
Unsupported Tests : 13
Unexpected Failures: 1437

Taking off that -DCMAKE_CXX_FLAGS=-Os makes the assertions go away. And copying Type.cpp.o from a build without -Os into a build that was configured with it also fixes them (where -b2 was a good build, and the current directory is a bad one):
cp -ai ../llvm-b2/lib/VMCore/CMakeFiles/LLVMCore.dir/Type.cpp.o lib/VMCore/CMakeFiles/LLVMCore.dir/

@efriedma-quic
Copy link
Collaborator

You can try splitting Type.cpp into two files, put half the definitions into one file, see which file contains the miscomputed function, etc.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Dec 27, 2011

An 'interesting' result on that front: Depending on how I split the functions between the two new files, sometimes the assertions disappear entirely. Still figuring out which combination of functions being in the same translation unit causes it...

@llvmbot
Copy link
Collaborator Author

llvmbot commented Dec 30, 2011

I split Type.cpp into two files. PointerType's constructor seems to be the culprit function, because moving it between the two files changes which object file needs to be replaced to fix the assertions. However, if it's in a file by itself, the assertions don't occur.

Right now, the minimal combination I found that causes failure is this, with just one other function definition in the file:

#include "LLVMContextImpl.h"
using namespace llvm;

void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
assert(isOpaque() && "Struct body already set!");

setSubclassData(getSubclassData() | SCDB_HasBody);
if (isPacked)
setSubclassData(getSubclassData() | SCDB_Packed);

Type *Elts = getContext().pImpl->
TypeAllocator.Allocate<Type
>(Elements.size());
memcpy(Elts, Elements.data(), sizeof(Elements[0])*Elements.size());

ContainedTys = Elts;
NumContainedTys = Elements.size();
}

PointerType::PointerType(Type *E, unsigned AddrSpace)
: SequentialType(PointerTyID, E) {
setSubclassData(AddrSpace);
}

@efriedma-quic
Copy link
Collaborator

Okay... at that point, all you can really do is try to separate out an executable testcase that crashes from the rest of LLVM, and file a bug in the gcc or Ubuntu bug tracker...

@llvmbot
Copy link
Collaborator Author

llvmbot commented Dec 31, 2011

Huh, I guess it's bitfield shenanigans going by this patch?

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20111226/134181.html

@efriedma-quic
Copy link
Collaborator

Yes, likely the same issue... did anyone actually file it against gcc, though?

@kaomoneus
Copy link
Contributor

PATCH
Guys, I fixed that. I posted it to llvm-commits. But it seems that it was deeply dived in posts ocean. So I repost it here:

The problem is in Type.h. The fields in Type class are declared in next
order:
TypeID ID : 8;
unsigned SubclassData : 24;
unsigned NumContainedTys;

Attempt to set new SubclassData value rewrites lowest byte in
NumContainedTys when -Os is set. GCC bug? Anyway setting SubclassData
with two workaround strings fixes the problem:

void setSubclassData(unsigned val) {
unsigned tmp = NumContainedTys; // Workaround for GCC -Os
SubclassData = val;
NumContainedTys = tmp; // Workaround for GCC -Os
// Ensure we don't have any accidental truncation.
assert(SubclassData == val && "Subclass data too large for field");
}

Probably there is another ways to protect NumContainedTys from overwritting?

Please find the patch in attachment for review.

-Stepan.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Dec 31, 2011

Yes, likely the same issue... did anyone actually file it against gcc, though?
I was goint to try and make a standalone single-file executable, but it's ridiculously complicated. So yeah, filed a bug with Ubuntu with the details for now:

https://bugs.launchpad.net/bugs/910363

@kaomoneus
Copy link
Contributor

Fixed in r147470

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 5, 2012

For the record, I just filed a bug with GCC:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51759

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

3 participants