Skip to content

Commit 1c0ddae

Browse files
committed
[AVR] Fix read of uninitialized variable AVRSubtarget:::ELFArch
Found by the LLVM MemorySanitizer tests when switching AVR to a default backend. ELFArch must be initialized before the call to initializeSubtargetDependencies(). The uninitialized read would occur deep within TableGen'd code.
1 parent 0ed0823 commit 1c0ddae

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

llvm/lib/Target/AVR/AVRSubtarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ 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), InstrInfo(), FrameLowering(),
32+
: AVRGenSubtargetInfo(TT, CPU, FS), ELFArch(0), InstrInfo(), FrameLowering(),
3333
TLInfo(TM, initializeSubtargetDependencies(CPU, FS, TM)), TSInfo(),
3434

3535
// Subtarget features
@@ -38,7 +38,7 @@ AVRSubtarget::AVRSubtarget(const Triple &TT, const std::string &CPU,
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), ELFArch(false), m_FeatureSetDummy(false) {
41+
m_hasTinyEncoding(false), m_FeatureSetDummy(false) {
4242
// Parse features string.
4343
ParseSubtargetFeatures(CPU, FS);
4444
}

llvm/lib/Target/AVR/AVRSubtarget.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ class AVRSubtarget : public AVRGenSubtargetInfo {
8181
}
8282

8383
private:
84+
85+
/// The ELF e_flags architecture.
86+
unsigned ELFArch;
87+
8488
AVRInstrInfo InstrInfo;
8589
AVRFrameLowering FrameLowering;
8690
AVRTargetLowering TLInfo;
@@ -107,9 +111,6 @@ class AVRSubtarget : public AVRGenSubtargetInfo {
107111
bool m_hasBREAK;
108112
bool m_hasTinyEncoding;
109113

110-
/// The ELF e_flags architecture.
111-
unsigned ELFArch;
112-
113114
// Dummy member, used by FeatureSet's. We cannot have a SubtargetFeature with
114115
// no variable, so we instead bind pseudo features to this variable.
115116
bool m_FeatureSetDummy;

0 commit comments

Comments
 (0)