From 2cf4b4de0c7b290bc52843d3aecc23ff496a8729 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Fri, 13 Mar 2020 00:51:30 +1300 Subject: [PATCH] [AVR] Fix reads of uninitialized variables from constructor of AVRSubtarget The initialization order was not correct. These bugs were discovered by valgrind. They appear to work fine in practice but this patch should unblock switching the AVR backend on by default as now a standard AVR llc invocation runs without memory errors. The AVRISelLowering constructor would run before the subtarget boolean fields were initialized to false. Now, the initialization order is correct. --- llvm/lib/Target/AVR/AVRSubtarget.cpp | 9 ++++++--- llvm/lib/Target/AVR/AVRSubtarget.h | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Target/AVR/AVRSubtarget.cpp b/llvm/lib/Target/AVR/AVRSubtarget.cpp index be5c4c06225b7..bd4a3fcb5fcd9 100644 --- a/llvm/lib/Target/AVR/AVRSubtarget.cpp +++ b/llvm/lib/Target/AVR/AVRSubtarget.cpp @@ -29,8 +29,8 @@ namespace llvm { AVRSubtarget::AVRSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const AVRTargetMachine &TM) - : AVRGenSubtargetInfo(TT, CPU, FS), ELFArch(0), InstrInfo(), FrameLowering(), - TLInfo(TM, initializeSubtargetDependencies(CPU, FS, TM)), TSInfo(), + : AVRGenSubtargetInfo(TT, CPU, FS), + ELFArch(0), // Subtarget features m_hasSRAM(false), m_hasJMPCALL(false), m_hasIJMPCALL(false), @@ -38,7 +38,10 @@ AVRSubtarget::AVRSubtarget(const Triple &TT, const std::string &CPU, m_hasMOVW(false), m_hasLPM(false), m_hasLPMX(false), m_hasELPM(false), m_hasELPMX(false), m_hasSPM(false), m_hasSPMX(false), m_hasDES(false), m_supportsRMW(false), m_supportsMultiplication(false), m_hasBREAK(false), - m_hasTinyEncoding(false), m_FeatureSetDummy(false) { + m_hasTinyEncoding(false), m_FeatureSetDummy(false), + + InstrInfo(), FrameLowering(), + TLInfo(TM, initializeSubtargetDependencies(CPU, FS, TM)), TSInfo() { // Parse features string. ParseSubtargetFeatures(CPU, FS); } diff --git a/llvm/lib/Target/AVR/AVRSubtarget.h b/llvm/lib/Target/AVR/AVRSubtarget.h index aa813a15dc0a4..ca4167fcb3359 100644 --- a/llvm/lib/Target/AVR/AVRSubtarget.h +++ b/llvm/lib/Target/AVR/AVRSubtarget.h @@ -85,11 +85,6 @@ class AVRSubtarget : public AVRGenSubtargetInfo { /// The ELF e_flags architecture. unsigned ELFArch; - AVRInstrInfo InstrInfo; - AVRFrameLowering FrameLowering; - AVRTargetLowering TLInfo; - AVRSelectionDAGInfo TSInfo; - // Subtarget feature settings // See AVR.td for details. bool m_hasSRAM; @@ -114,6 +109,11 @@ class AVRSubtarget : public AVRGenSubtargetInfo { // Dummy member, used by FeatureSet's. We cannot have a SubtargetFeature with // no variable, so we instead bind pseudo features to this variable. bool m_FeatureSetDummy; + + AVRInstrInfo InstrInfo; + AVRFrameLowering FrameLowering; + AVRTargetLowering TLInfo; + AVRSelectionDAGInfo TSInfo; }; } // end namespace llvm