[PATCH] D44802: Add the ShadowCallStack pass

Vlad Tsyrklevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 29 11:47:52 PDT 2018


vlad.tsyrklevich added inline comments.


================
Comment at: lib/Target/X86/ShadowCallStack.cpp:95
+  if (MBB->empty())
+    Noop = BuildMI(MBB, DL, TII->get(X86::NOOP));
+
----------------
pcc wrote:
> vlad.tsyrklevich wrote:
> > pcc wrote:
> > > vlad.tsyrklevich wrote:
> > > > eugenis wrote:
> > > > > AFAIK you can do it without a dummy instruction by using the iterator form of BuildMI and passing MBB->end() or MBB->begin() in case of the empty basic block.
> > > > You could use the MBB->begin() form and insert them backwards, but for the sake of readability I insert them forwards.
> > > I would imagine that you could save the result of `MBB->begin()` and use that to insert instructions forwards, as it should always refer to what used to be the first instruction. Does that not work?
> > Sorry, let me be more clear. BuildMI() has two forms: one to add to the end of an MBB and one to add before a given instruction in the MBB. That means that for an empty MBB we can't insert instructions in forwards order without inserting a fake instruction to insert behind or using two different forms to insert the same instructions (one inserting behind the first instruction and the other always using the add-to-the-end form.)
> But there is another form that takes an iterator.
> 
> http://llvm-cs.pcc.me.uk/include/llvm/CodeGen/MachineInstrBuilder.h#313
> 
> Can you pass the iterator that you previously got from `MBB->begin()` to it?
Huh, I didn't think this form would work because the iterator would be invalidated between MBB insertions but it looks like that's not the case for ilists so this form does work.


Repository:
  rL LLVM

https://reviews.llvm.org/D44802





More information about the llvm-commits mailing list