Skip to content

Commit

Permalink
[AVR] Fix reads of uninitialized variables from constructor of AVRSub…
Browse files Browse the repository at this point in the history
…target

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.
  • Loading branch information
dylanmckay committed Mar 12, 2020
1 parent d5edcb9 commit 2cf4b4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions llvm/lib/Target/AVR/AVRSubtarget.cpp
Expand Up @@ -29,16 +29,19 @@ 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),
m_hasEIJMPCALL(false), m_hasADDSUBIW(false), m_hasSmallStack(false),
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);
}
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Target/AVR/AVRSubtarget.h
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 2cf4b4d

Please sign in to comment.