[AVR] Fix read of uninitialized variable AVRSubtarget:::ELFArch
authorDylan McKay <me@dylanmckay.io>
Thu, 12 Mar 2020 11:03:30 +0000 (00:03 +1300)
committerDylan McKay <me@dylanmckay.io>
Thu, 12 Mar 2020 11:09:13 +0000 (00:09 +1300)
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.

llvm/lib/Target/AVR/AVRSubtarget.cpp
llvm/lib/Target/AVR/AVRSubtarget.h

index 6a41036..be5c4c0 100644 (file)
@@ -29,7 +29,7 @@ namespace llvm {
 
 AVRSubtarget::AVRSubtarget(const Triple &TT, const std::string &CPU,
                            const std::string &FS, const AVRTargetMachine &TM)
-    : AVRGenSubtargetInfo(TT, CPU, FS), InstrInfo(), FrameLowering(),
+    : AVRGenSubtargetInfo(TT, CPU, FS), ELFArch(0), InstrInfo(), FrameLowering(),
       TLInfo(TM, initializeSubtargetDependencies(CPU, FS, TM)), TSInfo(),
 
       // Subtarget features
@@ -38,7 +38,7 @@ 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), ELFArch(false), m_FeatureSetDummy(false) {
+      m_hasTinyEncoding(false), m_FeatureSetDummy(false) {
   // Parse features string.
   ParseSubtargetFeatures(CPU, FS);
 }
index da9289a..aa813a1 100644 (file)
@@ -81,6 +81,10 @@ public:
   }
 
 private:
+
+  /// The ELF e_flags architecture.
+  unsigned ELFArch;
+
   AVRInstrInfo InstrInfo;
   AVRFrameLowering FrameLowering;
   AVRTargetLowering TLInfo;
@@ -107,9 +111,6 @@ private:
   bool m_hasBREAK;
   bool m_hasTinyEncoding;
 
-  /// The ELF e_flags architecture.
-  unsigned ELFArch;
-
   // 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;