summaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
AgeCommit message (Collapse)Author
2015-06-17Move the personality function from LandingPadInst to FunctionDavid Majnemer
The personality routine currently lives in the LandingPadInst. This isn't desirable because: - All LandingPadInsts in the same function must have the same personality routine. This means that each LandingPadInst beyond the first has an operand which produces no additional information. - There is ongoing work to introduce EH IR constructs other than LandingPadInst. Moving the personality routine off of any one particular Instruction and onto the parent function seems a lot better than have N different places a personality function can sneak onto an exceptional function. Differential Revision: http://reviews.llvm.org/D10429 llvm-svn: 239940
2015-06-17Handle forward referenced function when streaming bitcode.Rafael Espindola
Without this the included unit test would assert in assert(BasicBlockFwdRefs.empty() && "Unresolved blockaddress fwd references"); llvm-svn: 239871
2015-06-17Handle MaterializeAll in getLazyBitcodeModuleImpl. NFC.Rafael Espindola
This just handles both cases in the same place. Extracted from a patch by Karl Schimpf. llvm-svn: 239870
2015-06-16Use std::unique_ptr to manage the DataStreamer in bitcode parsing.Rafael Espindola
We were already deleting it, this just makes it explicit. llvm-svn: 239867
2015-06-16Return a unique_ptr from getLazyBitcodeModule and parseBitcodeFile. NFC.Rafael Espindola
llvm-svn: 239858
2015-06-16Improve handling of end of file in the bitcode reader.Rafael Espindola
Before this patch the bitcode reader would read a module from a file that contained in order: * Any number of non MODULE_BLOCK sub blocks. * One MODULE_BLOCK * Any number of non MODULE_BLOCK sub blocks. * 4 '\n' characters to handle OS X's ranlib. Since we support lazy reading of modules, any information that is relevant for the module has to be in the MODULE_BLOCK or before it. We don't gain anything from checking what is after. This patch then changes the reader to stop once the MODULE_BLOCK has been successfully parsed. This avoids the ugly special case for .bc files in an archive and makes it easier to embed bitcode files. llvm-svn: 239845
2015-06-15Protection against stack-based memory corruption errors using SafeStackPeter Collingbourne
This patch adds the safe stack instrumentation pass to LLVM, which separates the program stack into a safe stack, which stores return addresses, register spills, and local variables that are statically verified to be accessed in a safe way, and the unsafe stack, which stores everything else. Such separation makes it much harder for an attacker to corrupt objects on the safe stack, including function pointers stored in spilled registers and return addresses. You can find more information about the safe stack, as well as other parts of or control-flow hijack protection technique in our OSDI paper on code-pointer integrity (http://dslab.epfl.ch/pubs/cpi.pdf) and our project website (http://levee.epfl.ch). The overhead of our implementation of the safe stack is very close to zero (0.01% on the Phoronix benchmarks). This is lower than the overhead of stack cookies, which are supported by LLVM and are commonly used today, yet the security guarantees of the safe stack are strictly stronger than stack cookies. In some cases, the safe stack improves performance due to better cache locality. Our current implementation of the safe stack is stable and robust, we used it to recompile multiple projects on Linux including Chromium, and we also recompiled the entire FreeBSD user-space system and more than 100 packages. We ran unit tests on the FreeBSD system and many of the packages and observed no errors caused by the safe stack. The safe stack is also fully binary compatible with non-instrumented code and can be applied to parts of a program selectively. This patch is our implementation of the safe stack on top of LLVM. The patches make the following changes: - Add the safestack function attribute, similar to the ssp, sspstrong and sspreq attributes. - Add the SafeStack instrumentation pass that applies the safe stack to all functions that have the safestack attribute. This pass moves all unsafe local variables to the unsafe stack with a separate stack pointer, whereas all safe variables remain on the regular stack that is managed by LLVM as usual. - Invoke the pass as the last stage before code generation (at the same time the existing cookie-based stack protector pass is invoked). - Add unit tests for the safe stack. Original patch by Volodymyr Kuznetsov and others at the Dependable Systems Lab at EPFL; updates and upstreaming by myself. Differential Revision: http://reviews.llvm.org/D6094 llvm-svn: 239761
2015-06-15Don't indent inside a namespace. NFC.Rafael Espindola
llvm-svn: 239760
2015-06-15Replace @ with the more common \. NFC.Rafael Espindola
llvm-svn: 239759
2015-06-15Don't repeat names in comments and start functions with a lower case letter.Rafael Espindola
llvm-svn: 239756
2015-06-15Cleanup the constructor of BitcodeReader. NFC.Rafael Espindola
Use the same argument names as the members. Use default member initializes. Extracted from a patch by Karl Schimpf. llvm-svn: 239749
2015-06-12Rangify two for loops in BitcodeReader.cpp.Yaron Keren
llvm-svn: 239627
2015-06-06Use early return idiom. NFCFilipe Cabecinhas
llvm-svn: 239228
2015-06-03[BitcodeReader] Diagnose type mismatches with aliasesFilipe Cabecinhas
Bug found with AFL fuzz. llvm-svn: 238895
2015-06-03[BitcodeReader] Check vector size before trying to create a VectorTypeFilipe Cabecinhas
Bug found with AFL fuzz llvm-svn: 238891
2015-05-30[BitcodeReader] Change an assert to a call to a call to Error()Filipe Cabecinhas
It's reachable from user input. Bug found with AFL fuzz. llvm-svn: 238633
2015-05-29Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial typesBenjamin Kramer
If the type isn't trivially moveable emplace can skip a potentially expensive move. It also saves a couple of characters. Call sites were found with the ASTMatcher + some semi-automated cleanup. memberCallExpr( argumentCountIs(1), callee(methodDecl(hasName("push_back"))), on(hasType(recordDecl(has(namedDecl(hasName("emplace_back")))))), hasArgument(0, bindTemporaryExpr( hasType(recordDecl(hasNonTrivialDestructor())), has(constructExpr()))), unless(isInTemplateInstantiation())) No functional change intended. llvm-svn: 238602
2015-05-27[BitcodeReader] Change assert to report_fatal_errorFilipe Cabecinhas
It can be triggered by user input. Bug found with AFL fuzz. llvm-svn: 238272
2015-05-26Add initial support for the convergent attribute.Owen Anderson
llvm-svn: 238264
2015-05-26[BitcodeReader] Sanity check on Comdat IDFilipe Cabecinhas
Shouldn't be an assert, since user input can trigger it. Bug found with AFL fuzz. llvm-svn: 238261
2015-05-21IR / debug info: Add a DWOId field to DICompileUnit,Adrian Prantl
so DWARF skeleton CUs can be expression in IR. A skeleton CU is a (typically empty) DW_TAG_compile_unit that has a DW_AT_(GNU)_dwo_name and a DW_AT_(GNU)_dwo_id attribute. It is used to refer to external debug info. This is a prerequisite for clang module debugging as discussed in http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-November/040076.html. In order to refer to external types stored in split DWARF (dwo) objects, such as clang modules, we need to emit skeleton CUs, which identify the dwarf object (i.e., the clang module) by filename (the SplitDebugFilename) and a hash value, the dwo_id. This patch only contains the IR changes. The idea is that a CUs with a non-zero dwo_id field will be emitted together with a DW_AT_GNU_dwo_name and DW_AT_GNU_dwo_id attribute. http://reviews.llvm.org/D9488 rdar://problem/20091852 llvm-svn: 237949
2015-05-19[BitcodeReader] Error out if we read an invalid function argument typeFilipe Cabecinhas
Bug found with AFL fuzz. llvm-svn: 237650
2015-05-18[BitcodeReader] Make sure the type of the inserted value matches the type of ↵Filipe Cabecinhas
the aggregate at those indices Bug found with AFL-fuzz. llvm-svn: 237628
2015-05-18Extract the load/store type verification to a separate function.Filipe Cabecinhas
Summary: Added isLoadableOrStorableType to PointerType. We were doing some checks in some places, occasionally assert()ing instead of telling the caller. With this patch, I'm putting all type checking in the same place for load/store type instructions, and verifying the same thing every time. I also added a check for load/store of a function type. Applied extracted check to Load, Store, and Cmpxcg. I don't have exhaustive tests for all of these, but all Error() calls in TypeCheckLoadStoreInst are being tested (in invalid.test). Reviewers: dblaikie, rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9785 llvm-svn: 237619
2015-05-16[BitcodeReader] Don't allow INSERTVAL/EXTRACTVAL with 0 indicesFilipe Cabecinhas
This would trigger an assertion later. Bug found with AFL fuzz. llvm-svn: 237494
2015-05-15Remove redundant checks. NFCFilipe Cabecinhas
llvm-svn: 237488
2015-05-15While in GlobalValue fix the function(s) that don't follow theEric Christopher
naming convention and update users. llvm-svn: 237461
2015-05-08[opaque pointer type] Explicit pointee type for GEPOperator/GEPConstantExpr.David Blaikie
Also a couple of other changes to avoid use of PointerType::getElementType here & there too. llvm-svn: 236799
2015-04-30Don't overflow GCTableFilipe Cabecinhas
Summary: Bug found with AFL fuzz. Reviewers: rafael, dexonsmith Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9361 llvm-svn: 236200
2015-04-30Make sure Op->getType() is a PointerType before we cast<> it.Filipe Cabecinhas
Bug found with AFL fuzz. llvm-svn: 236193
2015-04-30Make sure we don't resize(0) when we get a fwdref with Idx == UINT_MAXFilipe Cabecinhas
Make it an error instead. Bug found with AFL fuzz. llvm-svn: 236190
2015-04-29[opaque pointer type] Pass GlobalAlias the actual pointer type rather than ↵David Blaikie
decomposing it into pointee type + address space Many of the callers already have the pointer type anyway, and for the couple of callers that don't it's pretty easy to call PointerType::get on the pointee type and address space. This avoids LLParser from using PointerType::getElementType when parsing GlobalAliases from IR. llvm-svn: 236160
2015-04-29IR: Give 'DI' prefix to debug info metadataDuncan P. N. Exon Smith
Finish off PR23080 by renaming the debug info IR constructs from `MD*` to `DI*`. The last of the `DIDescriptor` classes were deleted in r235356, and the last of the related typedefs removed in r235413, so this has all baked for about a week. Note: If you have out-of-tree code (like a frontend), I recommend that you get everything compiling and tests passing with the *previous* commit before updating to this one. It'll be easier to keep track of what code is using the `DIDescriptor` hierarchy and what you've already updated, and I think you're extremely unlikely to insert bugs. YMMV of course. Back to *this* commit: I did this using the rename-md-di-nodes.sh upgrade script I've attached to PR23080 (both code and testcases) and filtered through clang-format-diff.py. I edited the tests for test/Assembler/invalid-generic-debug-node-*.ll by hand since the columns were off-by-three. It should work on your out-of-tree testcases (and code, if you've followed the advice in the previous paragraph). Some of the tests are in badly named files now (e.g., test/Assembler/invalid-mdcompositetype-missing-tag.ll should be 'dicompositetype'); I'll come back and move the files in a follow-up commit. llvm-svn: 236120
2015-04-29Use an "early return" idiom for the error case. NFCFilipe Cabecinhas
llvm-svn: 236080
2015-04-29Check that we have a valid PointerType element type before calling get()Filipe Cabecinhas
Same as r236073 but for PointerType. Bug found with AFL fuzz. llvm-svn: 236079
2015-04-29Use the ArrayType member function for array element types.Filipe Cabecinhas
ArrayType and StructType accept the same types, so no test. llvm-svn: 236078
2015-04-29Make sure that isValidElementType(Type) before calling ↵Filipe Cabecinhas
{Array,Struct}Type::get(Type) Bug found with AFL fuzz. llvm-svn: 236073
2015-04-28Relax an assert when there's a type mismatch in forward referencesFilipe Cabecinhas
Summary: We don't seem to need to assert here, since this function's callers expect to get a nullptr on error. This way we don't assert on user input. Bug found with AFL fuzz. Reviewers: rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9308 llvm-svn: 236027
2015-04-28[opaque pointer type] Encode the allocated type of an alloca rather than its ↵David Blaikie
pointer result type. llvm-svn: 235998
2015-04-28[opaque pointer type] Encode the pointee type in the bitcode for 'cmpxchg'David Blaikie
As a space optimization, this instruction would just encode the pointer type of the first operand and use the knowledge that the second and third operands would be of the pointee type of the first. When typed pointers go away, this assumption will no longer be available - so encode the type of the second operand explicitly and rely on that for the third. Test case added to demonstrate the backwards compatibility concern, which only comes up when the definition of the second operand comes after the use (hence the weird basic block sequence) - at which point the type needs to be explicitly encoded in the bitcode and the record length changes to accommodate this. llvm-svn: 235966
2015-04-27[opaque pointer type] encode the pointee type of global variablesDavid Blaikie
Use a few extra bits in the const field (after widening it from a fixed single bit) to stash the address space which is no longer provided by the type (and an extra bit in there to specify that we're using that new encoding). llvm-svn: 235911
2015-04-24IR: Add assembly/bitcode support for function metadata attachmentsDuncan P. N. Exon Smith
Add serialization support for function metadata attachments (added in r235783). The syntax is: define @foo() !attach !0 { Metadata attachments are only allowed on functions with bodies. Since they come before the `{`, they're not really part of the body; since they require a body, they're not really part of the header. In `LLParser` I gave them a separate function called from `ParseDefine()`, `ParseOptionalFunctionMetadata()`. In bitcode, I'm using the same `METADATA_ATTACHMENT` record used by instructions. Instruction metadata attachments are included in a special "attachment" block at the end of a `Function`. The attachment records are laid out like this: InstID (KindID MetadataID)+ Note that these records always have an odd number of fields. The new code takes advantage of this to recognize function attachments (which don't need an instruction ID): (KindID MetadataID)+ This means we can use the same attachment block already used for instructions. This is part of PR23340. llvm-svn: 235785
2015-04-24[opaque pointer type] bitcode: add explicit callee type to invoke instructionsDavid Blaikie
llvm-svn: 235735
2015-04-24[BitcodeReader] Fix asserts when we read a non-vector type for ↵Filipe Cabecinhas
insert/extract/shuffle Added some additional checking for vector types + tests. Bug found with AFL fuzz. llvm-svn: 235710
2015-04-23Recommit r235458: [opaque pointer type] Avoid using ↵David Blaikie
PointerType::getElementType for a few cases of CallInst (reverted in r235533) Original commit message: "Calls to llvm::Value::mutateType are becoming extra-sensitive now that instructions have extra type information that will not be derived from operands or result type (alloca, gep, load, call/invoke, etc... ). The special-handling for mutateType will get more complicated as this work continues - it might be worth making mutateType virtual & pushing the complexity down into the classes that need special handling. But with only two significant uses of mutateType (vectorization and linking) this seems OK for now. Totally open to ideas/suggestions/improvements, of course. With this, and a bunch of exceptions, we can roundtrip an indirect call site through bitcode and IR. (a direct call site is actually trickier... I haven't figured out how to deal with the IR deserializer's lazy construction of Function/GlobalVariable decl's based on the type of the entity which means looking through the "pointer to T" type referring to the global)" The remapping done in ValueMapper for LTO was insufficient as the types weren't correctly mapped (though I was using the post-mapped operands, some of those operands might not have been mapped yet so the type wouldn't be post-mapped yet). Instead use the pre-mapped type and explicitly map all the types. llvm-svn: 235651
2015-04-22Revert "[opaque pointer type] Avoid using PointerType::getElementType for a ↵David Blaikie
few cases of CallInst" This reverts commit r235458. It looks like this might be breaking something LTO-ish. Looking into it & will recommit with a fix/test case/etc once I've got more to go on. llvm-svn: 235533
2015-04-22Have more strict type checks when creating BinOp nodes in BitcodeReaderFilipe Cabecinhas
Summary: Bug found with AFL. Reviewers: rafael, bkramer Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9015 llvm-svn: 235489
2015-04-22[opaque pointer types] Serialize the value type for atomic store instructionsDavid Blaikie
Without pointee types the space optimization of storing only the pointer type and not the value type won't be viable - so add the extra type information that would be missing. llvm-svn: 235475
2015-04-22[opaque pointer types] Serialize the value type for store instructionsDavid Blaikie
Without pointee types the space optimization of storing only the pointer type and not the value type won't be viable - so add the extra type information that would be missing. Storeatomic coming soon. llvm-svn: 235474
2015-04-21[opaque pointer type] Avoid using PointerType::getElementType for a few ↵David Blaikie
cases of CallInst Calls to llvm::Value::mutateType are becoming extra-sensitive now that instructions have extra type information that will not be derived from operands or result type (alloca, gep, load, call/invoke, etc... ). The special-handling for mutateType will get more complicated as this work continues - it might be worth making mutateType virtual & pushing the complexity down into the classes that need special handling. But with only two significant uses of mutateType (vectorization and linking) this seems OK for now. Totally open to ideas/suggestions/improvements, of course. With this, and a bunch of exceptions, we can roundtrip an indirect call site through bitcode and IR. (a direct call site is actually trickier... I haven't figured out how to deal with the IR deserializer's lazy construction of Function/GlobalVariable decl's based on the type of the entity which means looking through the "pointer to T" type referring to the global) llvm-svn: 235458