Skip to content

Commit 954d0a9

Browse files
committed
[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.
1 parent 1c0ddae commit 954d0a9

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

llvm/lib/Target/AVR/AVRSubtarget.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ namespace llvm {
2929

3030
AVRSubtarget::AVRSubtarget(const Triple &TT, const std::string &CPU,
3131
const std::string &FS, const AVRTargetMachine &TM)
32-
: AVRGenSubtargetInfo(TT, CPU, FS), ELFArch(0), InstrInfo(), FrameLowering(),
33-
TLInfo(TM, initializeSubtargetDependencies(CPU, FS, TM)), TSInfo(),
32+
: AVRGenSubtargetInfo(TT, CPU, FS),
33+
ELFArch(0),
3434

3535
// Subtarget features
3636
m_hasSRAM(false), m_hasJMPCALL(false), m_hasIJMPCALL(false),
3737
m_hasEIJMPCALL(false), m_hasADDSUBIW(false), m_hasSmallStack(false),
3838
m_hasMOVW(false), m_hasLPM(false), m_hasLPMX(false), m_hasELPM(false),
3939
m_hasELPMX(false), m_hasSPM(false), m_hasSPMX(false), m_hasDES(false),
4040
m_supportsRMW(false), m_supportsMultiplication(false), m_hasBREAK(false),
41-
m_hasTinyEncoding(false), m_FeatureSetDummy(false) {
41+
m_hasTinyEncoding(false), m_FeatureSetDummy(false),
42+
43+
InstrInfo(), FrameLowering(),
44+
TLInfo(TM, initializeSubtargetDependencies(CPU, FS, TM)), TSInfo() {
4245
// Parse features string.
4346
ParseSubtargetFeatures(CPU, FS);
4447
}

llvm/lib/Target/AVR/AVRSubtarget.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ class AVRSubtarget : public AVRGenSubtargetInfo {
8585
/// The ELF e_flags architecture.
8686
unsigned ELFArch;
8787

88-
AVRInstrInfo InstrInfo;
89-
AVRFrameLowering FrameLowering;
90-
AVRTargetLowering TLInfo;
91-
AVRSelectionDAGInfo TSInfo;
92-
9388
// Subtarget feature settings
9489
// See AVR.td for details.
9590
bool m_hasSRAM;
@@ -114,6 +109,11 @@ class AVRSubtarget : public AVRGenSubtargetInfo {
114109
// Dummy member, used by FeatureSet's. We cannot have a SubtargetFeature with
115110
// no variable, so we instead bind pseudo features to this variable.
116111
bool m_FeatureSetDummy;
112+
113+
AVRInstrInfo InstrInfo;
114+
AVRFrameLowering FrameLowering;
115+
AVRTargetLowering TLInfo;
116+
AVRSelectionDAGInfo TSInfo;
117117
};
118118

119119
} // end namespace llvm

0 commit comments

Comments
 (0)