[llvm] 2cf4b4d - [AVR] Fix reads of uninitialized variables from constructor of AVRSubtarget

Dylan McKay via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 12 04:58:13 PDT 2020


Author: Dylan McKay
Date: 2020-03-13T00:57:19+13:00
New Revision: 2cf4b4de0c7b290bc52843d3aecc23ff496a8729

URL: https://github.com/llvm/llvm-project/commit/2cf4b4de0c7b290bc52843d3aecc23ff496a8729
DIFF: https://github.com/llvm/llvm-project/commit/2cf4b4de0c7b290bc52843d3aecc23ff496a8729.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AVR/AVRSubtarget.cpp b/llvm/lib/Target/AVR/AVRSubtarget.cpp
index be5c4c06225b..bd4a3fcb5fcd 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 aa813a15dc0a..ca4167fcb335 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


        


More information about the llvm-commits mailing list