<br><br><div class="gmail_quote">On Fri, Sep 14, 2012 at 7:46 AM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
On Sep 12, 2012, at 1:58 PM, Alexander Kornienko <<a href="mailto:reviews@llvm-reviews.chandlerc.com">reviews@llvm-reviews.chandlerc.com</a>> wrote:<br>
</div></div><br>
+    // History of macro definitions for this identifier in chronological order.<br>
+    SmallVector<MacroInfo*, 8> MacroHistory;<br>
+    while (MI) {<br>
+      MacroHistory.push_back(MI);<br>
+      MI = MI->getPreviousDefinition();<br>
+    }<br>
+<br>
+    while (!MacroHistory.empty()) {<br>
+      MI = MacroHistory.pop_back_val();<br>
<br>
While this will write out all of the macro definitions and undefs, it has a few issues:<br>
<br>
  - There's no way for the reader to know that more than one macro definition is coming, and in fact the reader looks like it will only end up reading the *first* macro definition, rather than the *last* one. I suspect that #define'ing then #undef'ing a macro and defining it again within a PCH file will lead to the wrong macro definition in a client of that PCH file<br>
</blockquote><div><br></div><div>This seems to work correctly, at least the test I've added, should have broken if it didn't.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

  - It forces the reader to load in all of the macro history to get to the most recent one, which will be wasted effort in most cases: the vast majority of clients only care about the most recent macro definition and the rest of the definitions could be loaded lazily (e.g., the way we lazily load the body of a function). </blockquote>
<div><br></div><div>You mean adding another level of laziness above  ExternalPreprocessorSource::LoadMacroDefinition & Co? Are there reasons to believe it will help to solve more problems than it creates?</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  - This always writes out all of the macro history, even in chained PCH, where some of the macro history might already be in the original PCH. (This kind of issue matters more for modules).<br></blockquote><div><br></div>
<div>Any ideas how to fix this?</div><div><br></div></div>-- <br>
<div>Regards,</div><div>Alex</div>