[llvm] r296765 - [opt-viewer] Don't use __getattr__ for missing YAML attributes

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 2 09:00:54 PST 2017


Author: anemet
Date: Thu Mar  2 11:00:53 2017
New Revision: 296765

URL: http://llvm.org/viewvc/llvm-project?rev=296765&view=rev
Log:
[opt-viewer] Don't use __getattr__ for missing YAML attributes

__getattr__ does not work well with debugging.  If the attribute function has
a run-time error, a missing attribute is reported instead.

Modified:
    llvm/trunk/utils/opt-viewer/optrecord.py

Modified: llvm/trunk/utils/opt-viewer/optrecord.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/opt-viewer/optrecord.py?rev=296765&r1=296764&r2=296765&view=diff
==============================================================================
--- llvm/trunk/utils/opt-viewer/optrecord.py (original)
+++ llvm/trunk/utils/opt-viewer/optrecord.py Thu Mar  2 11:00:53 2017
@@ -40,11 +40,11 @@ class Remark(yaml.YAMLObject):
     # Work-around for http://pyyaml.org/ticket/154.
     yaml_loader = Loader
 
-    def __getattr__(self, name):
-        # If hotness is missing, assume 0
-        if name == 'Hotness':
-            return 0
-        raise AttributeError(name)
+    def initmissing(self):
+        if not hasattr(self, 'Hotness'):
+            self.Hotness = 0
+        if not hasattr(self, 'Args'):
+            self.Args = []
 
     @property
     def File(self):
@@ -146,6 +146,7 @@ def get_remarks(input_file):
     with open(input_file) as f:
         docs = yaml.load_all(f, Loader=Loader)
         for remark in docs:
+            remark.initmissing()
             # Avoid remarks withoug debug location or if they are duplicated
             if not hasattr(remark, 'DebugLoc') or remark.key in all_remarks:
                 continue




More information about the llvm-commits mailing list