1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00
llvm-mirror/include/llvm
Duncan P. N. Exon Smith bc2ac24566 ADT: Avoid relying on UB in ilist_node::getNextNode()
Re-implement `ilist_node::getNextNode()` and `getPrevNode()` without
relying on the sentinel having a "next" pointer.  Instead, get access to
the owning list and compare against the `begin()` and `end()` iterators.

This only works when the node *can* get access to the owning list.  The
new support is in `ilist_node_with_parent<>`, and any class `Ty`
inheriting from `ilist_node<NodeTy>` that wants `getNextNode()` and/or
`getPrevNode()` should inherit from
`ilist_node_with_parent<NodeTy, ParentTy>` instead.  The requirements:

  - `NodeTy` must have a `getParent()` function that returns the parent.
  - `ParentTy` must have a `getSublistAccess()` static that, given a(n
    ignored) `NodeTy*` (to determine which list), returns a member field
    pointer to the appropriate `ilist<>`.

This isn't the cleanest way to get access to the owning list, but it
leverages the API already used in the IR hierarchy (see, e.g.,
`Instruction::getSublistAccess()`).

If anyone feels like ripping out the calls to `getNextNode()` and
`getPrevNode()` and replacing with direct iterator logic, they can also
remove the access function, etc., but as an incremental step, I'm
maintaining the API where it's currently used in tree.

If these requirements are *not* met, call sites with access to the ilist
can call `iplist<NodeTy>::getNextNode(NodeTy*)` directly, as in
ilistTest.cpp.

Why rewrite this?

The old code was broken, calling `getNext()` on a sentinel that possibly
didn't have a "next" pointer at all!  The new code avoids that
particular flavour of UB (see the commit message for r252538 for more
details about the "lucky" memory layout that made this function so
interesting).

There's still some UB here: the end iterator gets downcast to `NodeTy*`,
even when it's a sentinel (which is typically
`ilist_half_node<NodeTy*>`).  I'll tackle that in follow-up commits.
See this llvm-dev thread for more details:
http://lists.llvm.org/pipermail/llvm-dev/2015-October/091115.html

What's the danger?

There might be some code that relies on `getNextNode()` or
`getPrevNode()` *never* returning `nullptr` -- i.e., that relies on them
being broken when the sentinel is an `ilist_half_node<NodeTy>`.  I tried
to root out those cases with the audits I did leading up to r252380, but
it's possible I missed one or two.  I hope not.

(If (1) you have out-of-tree code, (2) you've reverted r252380
temporarily, and (3) you get some weird crashes with this commit, then I
recommend un-reverting r252380 and auditing the compile errors looking
for "strange" implicit conversions.)

llvm-svn: 252694
2015-11-11 02:26:42 +00:00
..
ADT ADT: Avoid relying on UB in ilist_node::getNextNode() 2015-11-11 02:26:42 +00:00
Analysis Fix -Wdeprecated warnings due to the use of copy ops on SCEVPredicate derived class objects 2015-11-09 23:30:15 +00:00
AsmParser AsmParser: Save and restore the parsing state for types using SlotMapping. 2015-08-21 21:32:39 +00:00
Bitcode Add a method to the BitcodeReader to parse only the identification block 2015-11-09 02:46:41 +00:00
CodeGen ADT: Avoid relying on UB in ilist_node::getNextNode() 2015-11-11 02:26:42 +00:00
Config Make the default triple optional by allowing an empty string 2015-09-16 05:34:32 +00:00
DebugInfo [LLVMSymbolize] Reduce indentation by using helper function. NFC. 2015-11-04 00:30:26 +00:00
ExecutionEngine Revert "Revert "[Orc] Directly emit machine code for the x86 resolver block and trampolines."" 2015-11-03 16:40:37 +00:00
IR ADT: Avoid relying on UB in ilist_node::getNextNode() 2015-11-11 02:26:42 +00:00
IRReader Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
LibDriver LibDriver: Replace references to lld-link2 with lld-link. 2015-08-06 19:00:42 +00:00
LineEditor Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
Linker Restore "Support for ThinLTO function importing and symbol linking." 2015-11-03 00:14:15 +00:00
LTO Add a method to the BitcodeReader to parse only the identification block 2015-11-09 02:46:41 +00:00
MC ADT: Avoid relying on UB in ilist_node::getNextNode() 2015-11-11 02:26:42 +00:00
Object Fix llvm-nm(1) printing of llvm-bitcode files for -format darwin to match darwin’s nm(1). 2015-11-10 00:31:08 +00:00
Option [Option] Use an ArrayRef to store the Option Infos in OptTable. NFC 2015-10-21 16:30:42 +00:00
Passes Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
ProfileData [PGO] Make indexed value profile data more compact 2015-11-10 00:24:45 +00:00
Support Add templated read/write to support::endian. 2015-11-09 21:34:45 +00:00
TableGen Re-commit r247216: "Fix Clang-tidy misc-use-override warnings, other minor fixes" 2015-09-10 16:49:58 +00:00
Target don't repeat function/class/variable names in comments; NFC 2015-11-10 22:59:11 +00:00
Transforms Allow LLE/LD and the loop versioning infrastructure to use SCEV predicates 2015-11-09 13:26:09 +00:00
CMakeLists.txt
InitializePasses.h LLE 6/6: Add LoopLoadElimination pass 2015-11-03 23:50:08 +00:00
LinkAllIR.h
LinkAllPasses.h [PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible 2015-09-09 17:55:00 +00:00
module.modulemap llvm/module.modulemap: AVR.def should be textual header. 2015-10-24 00:25:18 +00:00
module.modulemap.build
Pass.h Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
PassAnalysisSupport.h [LPM] Teach the legacy pass manager to support *using* an analysis 2015-08-19 03:02:12 +00:00
PassInfo.h Reformat partially. 2015-10-05 04:46:30 +00:00
PassRegistry.h Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC) 2015-06-23 09:49:53 +00:00
PassSupport.h Support: Clean up TSan annotations. 2015-08-18 22:31:24 +00:00