Stop resetting SanitizeAddress in TargetMachine::resetTargetOptions. NFC.

Instead of doing that, create a temporary copy of MCTargetOptions and reset its
SanitizeAddress field based on the function's attribute every time an InlineAsm
instruction is emitted in AsmPrinter::EmitInlineAsm. 

This is part of the work to remove TargetMachine::resetTargetOptions (the FIXME
added to TargetMachine.cpp in r236009 explains why this function has to be
removed).

Differential Revision: http://reviews.llvm.org/D9570


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237412 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Akira Hatanaka
2015-05-15 00:20:44 +00:00
parent a1882d43c3
commit 634e01a3e5
4 changed files with 12 additions and 5 deletions

View File

@@ -53,6 +53,7 @@ class MCSection;
class MCStreamer; class MCStreamer;
class MCSubtargetInfo; class MCSubtargetInfo;
class MCSymbol; class MCSymbol;
class MCTargetOptions;
class MDNode; class MDNode;
class DwarfDebug; class DwarfDebug;
class Mangler; class Mangler;
@@ -498,6 +499,7 @@ private:
/// Emit a blob of inline asm to the output streamer. /// Emit a blob of inline asm to the output streamer.
void void
EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI, EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
const MCTargetOptions &MCOptions,
const MDNode *LocMDNode = nullptr, const MDNode *LocMDNode = nullptr,
InlineAsm::AsmDialect AsmDialect = InlineAsm::AD_ATT) const; InlineAsm::AsmDialect AsmDialect = InlineAsm::AD_ATT) const;

View File

@@ -225,7 +225,7 @@ bool AsmPrinter::doInitialization(Module &M) {
TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString())); TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString()));
OutStreamer->AddComment("Start of file scope inline assembly"); OutStreamer->AddComment("Start of file scope inline assembly");
OutStreamer->AddBlankLine(); OutStreamer->AddBlankLine();
EmitInlineAsm(M.getModuleInlineAsm()+"\n", *STI); EmitInlineAsm(M.getModuleInlineAsm()+"\n", *STI, TM.Options.MCOptions);
OutStreamer->AddComment("End of file scope inline assembly"); OutStreamer->AddComment("End of file scope inline assembly");
OutStreamer->AddBlankLine(); OutStreamer->AddBlankLine();
} }

View File

@@ -74,6 +74,7 @@ static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
/// EmitInlineAsm - Emit a blob of inline asm to the output streamer. /// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI, void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
const MCTargetOptions &MCOptions,
const MDNode *LocMDNode, const MDNode *LocMDNode,
InlineAsm::AsmDialect Dialect) const { InlineAsm::AsmDialect Dialect) const {
assert(!Str.empty() && "Can't emit empty inline asm block"); assert(!Str.empty() && "Can't emit empty inline asm block");
@@ -138,7 +139,7 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
// because it's not subtarget dependent. // because it's not subtarget dependent.
std::unique_ptr<MCInstrInfo> MII(TM.getTarget().createMCInstrInfo()); std::unique_ptr<MCInstrInfo> MII(TM.getTarget().createMCInstrInfo());
std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser( std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser(
TmpSTI, *Parser, *MII, TM.Options.MCOptions)); TmpSTI, *Parser, *MII, MCOptions));
if (!TAP) if (!TAP)
report_fatal_error("Inline asm not supported by this streamer because" report_fatal_error("Inline asm not supported by this streamer because"
" we don't have an asm parser for this target\n"); " we don't have an asm parser for this target\n");
@@ -488,7 +489,13 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
else else
EmitMSInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AP, LocCookie, OS); EmitMSInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AP, LocCookie, OS);
EmitInlineAsm(OS.str(), getSubtargetInfo(), LocMD, MI->getInlineAsmDialect()); // Reset SanitizeAddress based on the function's attribute.
MCTargetOptions MCOptions = TM.Options.MCOptions;
MCOptions.SanitizeAddress =
MF->getFunction()->hasFnAttribute(Attribute::SanitizeAddress);
EmitInlineAsm(OS.str(), getSubtargetInfo(), MCOptions, LocMD,
MI->getInlineAsmDialect());
// Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't
// enabled, so we use emitRawComment. // enabled, so we use emitRawComment.

View File

@@ -72,8 +72,6 @@ void TargetMachine::resetTargetOptions(const Function &F) const {
RESET_OPTION(NoInfsFPMath, "no-infs-fp-math"); RESET_OPTION(NoInfsFPMath, "no-infs-fp-math");
RESET_OPTION(NoNaNsFPMath, "no-nans-fp-math"); RESET_OPTION(NoNaNsFPMath, "no-nans-fp-math");
RESET_OPTION(DisableTailCalls, "disable-tail-calls"); RESET_OPTION(DisableTailCalls, "disable-tail-calls");
Options.MCOptions.SanitizeAddress = F.hasFnAttribute(Attribute::SanitizeAddress);
} }
/// getRelocationModel - Returns the code generation relocation model. The /// getRelocationModel - Returns the code generation relocation model. The