<div dir="ltr"><div>--- include/clang/AST/ASTConsumer.h<span class="" style="white-space:pre">  </span>(revision 182601)</div><div>+++ include/clang/AST/ASTConsumer.h<span class="" style="white-space:pre">       </span>(working copy)</div>
<div>@@ -92,6 +92,12 @@</div><div>   /// only exists to support Microsoft's #pragma comment(linker, "/foo").</div><div>   virtual void HandleLinkerOptionPragma(llvm::StringRef Opts) {}</div><div> </div><div>
+  /// \brief Handle a pragma that emits a mismatch identifier and value to the</div><div>+  /// object file for the linker to work with.  Currently, this only exists to</div><div>+  /// support Microsoft's #pragma detect_mismatch.</div>
<div>+  virtual void HandleDetectMismatch(llvm::StringRef Name,</div><div>+                                    llvm::StringRef Value) {}</div><div>+</div><div><br></div><div style>Should we avoid broadening the ASTConsumer interface?  If we lowered the option in Sema, then we could reuse HandleLinkerOptionPragma() without too much fuss.  But then we're doing codegen-like work in Sema.  I'd like a second opinion on this.  If we can do this in Sema, we can eliminate a lot of the plumbing for this and for #pragma comment(lib).</div>
<div style><br></div><div style><div>+/// \brief Handle the Microsoft \#pragma detect_mismatch extension.</div><div>+///</div><div>+/// The syntax is:</div><div>+/// \code</div><div>+///   #pragma detect_mismatch("name", "value")</div>
<div>+/// \endcode</div><div>+/// Where 'name' and 'value' are quoted strings.  The values are embedded in</div><div>+/// the object file and passed along to the linker.  If the linker detects a</div><div>
+/// mismatch in the object file's values for the given name, a LNK2038 error</div><div>+/// is emitted.  See MSDN for more details.</div><div><br></div><div style>Seems reasonable to link to MSDN here.</div><div><br>
</div><div>+void PragmaDetectMismatchHandler::HandlePragma(Preprocessor &PP,</div><div>+                                               PragmaIntroducerKind Introducer,</div><div>+                                               Token &Tok) {</div>
<div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 28, 2013 at 2:53 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ping?<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Fri, May 24, 2013 at 4:27 PM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
> This patch adds support for MSVC's #pragma detect_mismatch.  This<br>
> pragma emits a linker command into the object file which allows the<br>
> linker to ensure that there are no inconsistent object files being<br>
> linked together.  Eg)<br>
><br>
> // 1.cpp<br>
> #pragma detect_mismatch( "my_library", "1" )<br>
><br>
> // 2.cpp<br>
> #pragma detect_mismatch( "my_library", "2" )<br>
><br>
> If you link these files together with link.exe, you will get a linker<br>
> error (2038) pointing out that the values for my_library do not match.<br>
>  However, if 2.cpp had "1" in place of "2", the files would link<br>
> together without issue.<br>
><br>
> For more information, see MSDN:<br>
> <a href="http://msdn.microsoft.com/en-us/library/ee956429.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ee956429.aspx</a><br>
><br>
> The code was modeled after our existing support for passing linker<br>
> commands, and makes use of the fact that detect_mismatch uses the<br>
> /FAILIFMISMATCH linker option.<br>
><br>
> ~Aaron<br>
</div></div></blockquote></div><br></div>