diff --git a/llvm/include/llvm/CodeGen/IndirectThunks.h b/llvm/include/llvm/CodeGen/IndirectThunks.h --- a/llvm/include/llvm/CodeGen/IndirectThunks.h +++ b/llvm/include/llvm/CodeGen/IndirectThunks.h @@ -69,10 +69,11 @@ // IR-level constructs we already made. Create them and insert them into the // module. MachineFunction &MF = MMI.getOrCreateMachineFunction(*F); - MachineBasicBlock *EntryMBB = MF.CreateMachineBasicBlock(Entry); + // A MachineBasicBlock must not be created for the Entry block; code + // generation from an empty naked function in C source code also does not + // generate one. At least GlobalISel asserts if this invariant isn't + // respected. - // Insert EntryMBB into MF. It's not in the module until we do this. - MF.insert(MF.end(), EntryMBB); // Set MF properties. We never use vregs... MF.getProperties().set(MachineFunctionProperties::Property::NoVRegs); } diff --git a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp --- a/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp +++ b/llvm/lib/Target/AArch64/AArch64SLSHardening.cpp @@ -214,12 +214,9 @@ const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo(); - // Grab the entry MBB and erase any other blocks. O0 codegen appears to - // generate two bbs for the entry block. + assert (MF.size() == 1); MachineBasicBlock *Entry = &MF.front(); Entry->clear(); - while (MF.size() > 1) - MF.erase(std::next(MF.begin())); // These thunks need to consist of the following instructions: // __llvm_slsblr_thunk_xN: diff --git a/llvm/lib/Target/X86/X86IndirectThunks.cpp b/llvm/lib/Target/X86/X86IndirectThunks.cpp --- a/llvm/lib/Target/X86/X86IndirectThunks.cpp +++ b/llvm/lib/Target/X86/X86IndirectThunks.cpp @@ -79,12 +79,9 @@ createThunkFunction(MMI, R11LVIThunkName); } void populateThunk(MachineFunction &MF) { - // Grab the entry MBB and erase any other blocks. O0 codegen appears to - // generate two bbs for the entry block. + assert (MF.size() == 1); MachineBasicBlock *Entry = &MF.front(); Entry->clear(); - while (MF.size() > 1) - MF.erase(std::next(MF.begin())); // This code mitigates LVI by replacing each indirect call/jump with a // direct call/jump to a thunk that looks like: @@ -209,12 +206,9 @@ } const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo(); - // Grab the entry MBB and erase any other blocks. O0 codegen appears to - // generate two bbs for the entry block. + assert (MF.size() == 1); MachineBasicBlock *Entry = &MF.front(); Entry->clear(); - while (MF.size() > 1) - MF.erase(std::next(MF.begin())); MachineBasicBlock *CaptureSpec = MF.CreateMachineBasicBlock(Entry->getBasicBlock()); diff --git a/llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll b/llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll --- a/llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll +++ b/llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll @@ -1,7 +1,8 @@ ; RUN: llc -mattr=harden-sls-retbr,harden-sls-blr -verify-machineinstrs -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,HARDEN,ISBDSB,ISBDSBDAGISEL ; RUN: llc -mattr=harden-sls-retbr,harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,HARDEN,SB,SBDAGISEL ; RUN: llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,NOHARDEN - +; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr,harden-sls-blr -verify-machineinstrs -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,HARDEN,ISBDSB +; RUN: llc -global-isel -global-isel-abort=0 -mattr=harden-sls-retbr,harden-sls-blr -mattr=+sb -verify-machineinstrs -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,HARDEN,SB ; Function Attrs: norecurse nounwind readnone define dso_local i32 @double_return(i32 %a, i32 %b) local_unnamed_addr {