[PATCH] Support for #pragma detect_mismatch

Reid Kleckner rnk at google.com
Wed May 29 12:31:41 PDT 2013


--- include/clang/AST/ASTConsumer.h (revision 182601)
+++ include/clang/AST/ASTConsumer.h (working copy)
@@ -92,6 +92,12 @@
   /// only exists to support Microsoft's #pragma comment(linker, "/foo").
   virtual void HandleLinkerOptionPragma(llvm::StringRef Opts) {}

+  /// \brief Handle a pragma that emits a mismatch identifier and value to
the
+  /// object file for the linker to work with.  Currently, this only
exists to
+  /// support Microsoft's #pragma detect_mismatch.
+  virtual void HandleDetectMismatch(llvm::StringRef Name,
+                                    llvm::StringRef Value) {}
+

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).

+/// \brief Handle the Microsoft \#pragma detect_mismatch extension.
+///
+/// The syntax is:
+/// \code
+///   #pragma detect_mismatch("name", "value")
+/// \endcode
+/// Where 'name' and 'value' are quoted strings.  The values are embedded
in
+/// the object file and passed along to the linker.  If the linker detects
a
+/// mismatch in the object file's values for the given name, a LNK2038
error
+/// is emitted.  See MSDN for more details.

Seems reasonable to link to MSDN here.

+void PragmaDetectMismatchHandler::HandlePragma(Preprocessor &PP,
+                                               PragmaIntroducerKind
Introducer,
+                                               Token &Tok) {



On Tue, May 28, 2013 at 2:53 PM, Aaron Ballman <aaron at aaronballman.com>wrote:

> Ping?
>
> ~Aaron
>
> On Fri, May 24, 2013 at 4:27 PM, Aaron Ballman <aaron at aaronballman.com>
> wrote:
> > This patch adds support for MSVC's #pragma detect_mismatch.  This
> > pragma emits a linker command into the object file which allows the
> > linker to ensure that there are no inconsistent object files being
> > linked together.  Eg)
> >
> > // 1.cpp
> > #pragma detect_mismatch( "my_library", "1" )
> >
> > // 2.cpp
> > #pragma detect_mismatch( "my_library", "2" )
> >
> > If you link these files together with link.exe, you will get a linker
> > error (2038) pointing out that the values for my_library do not match.
> >  However, if 2.cpp had "1" in place of "2", the files would link
> > together without issue.
> >
> > For more information, see MSDN:
> > http://msdn.microsoft.com/en-us/library/ee956429.aspx
> >
> > The code was modeled after our existing support for passing linker
> > commands, and makes use of the fact that detect_mismatch uses the
> > /FAILIFMISMATCH linker option.
> >
> > ~Aaron
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130529/a9a6a8d5/attachment.html>


More information about the cfe-commits mailing list