<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Arial",sans-serif;
        color:#44546A;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#44546A">Yes, it does.  The intent of the Intel Compiler is to be completely compatible with the MSVC on windows, and with gcc on linux.  We have seen a number of instances,
 not in llvm, but in other open source software,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#44546A">where the #ifdefs used for __INTEL_COMPILER have been incorrect, and the code would have worked if the plain windows or gcc macros would have been used.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#44546A">I think David's solution is exactly right.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#44546A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#44546A">Kevin Smith<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#44546A"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><a name="_____replyseparator"></a><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> llvm-commits [mailto:llvm-commits-bounces@lists.llvm.org]
<b>On Behalf Of </b>Chandler Carruth via llvm-commits<br>
<b>Sent:</b> Wednesday, February 24, 2016 8:34 PM<br>
<b>To:</b> David Majnemer <david.majnemer@gmail.com>; Chandler Carruth <chandlerc@gmail.com><br>
<b>Cc:</b> llvm-commits <llvm-commits@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm] r261819 - [Support] Add a fancy helper function to get a static name for a type.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Ah, if ICC defines __GNUC__ then we're golden. I'll make that change, thanks!<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, Feb 24, 2016 at 8:32 PM David Majnemer via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">I think the handling for __INTEL_COMPILER is not quite right.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Intel's compiler for Windows, icl, also defines __INTEL_COMPILER.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">While icl defines __PRETTY_FUNCTION__, it provides behavior compatible with __FUNCSIG__.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Given that icc defines __GNUC__ and icl defines _MSC_VER, I'd suggest removing the defined(__INTEL_COMPILER).  I think the other checks will do the right thing.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Wed, Feb 24, 2016 at 7:58 PM, Chandler Carruth via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Author: chandlerc<br>
Date: Wed Feb 24 21:58:21 2016<br>
New Revision: 261819<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=261819&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=261819&view=rev</a><br>
Log:<br>
[Support] Add a fancy helper function to get a static name for a type.<br>
<br>
This extracts the type name from __PRETTY_FUNCTION__ for compilers that<br>
support it (I've opted Clang, GCC, and ICC into this as I've tested that<br>
they work) and from __FUNCSIG__ which is very similar on MSVC. The<br>
routine falls back gracefully on a stub "UNKNOWN_TYPE" string with<br>
compilers or formats it doesn't understand.<br>
<br>
This should be enough for a lot of common cases in LLVM where the real<br>
goal is just to log or print a type name as a debugging aid, and save<br>
a ton of boilerplate in the process. Notably, I'm planning to use this<br>
to remove all the getName() boiler plate from the new pass manager.<br>
<br>
The design and implementation is based on a bunch of advice and<br>
discussion with Richard Smith and experimenting with most versions of<br>
Clang and GCC. David Majnemer also provided excellent advice on how best<br>
to do this with MSVC. Richard also checked that ICC does something<br>
reasonable and I'll watch the build bots for other compilers. It'd be<br>
great if someone could contribute logic for xlC and/or other toolchains.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D17565" target="_blank">http://reviews.llvm.org/D17565</a><br>
<br>
Added:<br>
    llvm/trunk/include/llvm/Support/TypeName.h<br>
    llvm/trunk/unittests/Support/TypeNameTest.cpp<br>
Modified:<br>
    llvm/trunk/unittests/Support/CMakeLists.txt<br>
<br>
Added: llvm/trunk/include/llvm/Support/TypeName.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TypeName.h?rev=261819&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TypeName.h?rev=261819&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/TypeName.h (added)<br>
+++ llvm/trunk/include/llvm/Support/TypeName.h Wed Feb 24 21:58:21 2016<br>
@@ -0,0 +1,65 @@<br>
+//===- TypeName.h -----------------------------------------------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_SUPPORT_TYPENAME_H<br>
+#define LLVM_SUPPORT_TYPENAME_H<br>
+<br>
+#include "llvm/ADT/StringRef.h"<br>
+<br>
+namespace llvm {<br>
+<br>
+/// We provide a function which tries to compute the (demangled) name of a type<br>
+/// statically.<br>
+///<br>
+/// This routine may fail on some platforms or for particularly unusual types.<br>
+/// Do not use it for anything other than logging and debugging aids. It isn't<br>
+/// portable or dependendable in any real sense.<br>
+///<br>
+/// The returned StringRef will point into a static storage duration string.<br>
+/// However, it may not be null terminated and may be some strangely aligned<br>
+/// inner substring of a larger string.<br>
+template <typename DesiredTypeName><br>
+inline StringRef getTypeName() {<br>
+#if defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER)<br>
+  StringRef Name = __PRETTY_FUNCTION__;<br>
+<br>
+  StringRef Key = "DesiredTypeName = ";<br>
+  Name = Name.substr(Name.find(Key));<br>
+  assert(!Name.empty() && "Unable to find the template parameter!");<br>
+  Name = Name.drop_front(Key.size());<br>
+<br>
+  assert(Name.endswith("]") && "Name doesn't end in the substitution key!");<br>
+  return Name.drop_back(1);<br>
+#elif defined(_MSC_VER)<br>
+  StringRef Name = __FUNCSIG__;<br>
+<br>
+  StringRef Key = "getTypeName<";<br>
+  Name = Name.substr(Name.find(Key));<br>
+  assert(!Name.empty() && "Unable to find the function name!");<br>
+  Name = Name.drop_front(Key.size());<br>
+<br>
+  for (StringRef Prefix : {"class ", "struct ", "union ", "enum "})<br>
+    if (Name.startswith(Prefix)) {<br>
+      Name = Name.drop_front(Prefix.size());<br>
+      break;<br>
+    }<br>
+<br>
+  auto AnglePos = Name.rfind('>');<br>
+  assert(AnglePos != StringRef::npos && "Unable to find the closing '>'!");<br>
+  return Name.substr(0, AnglePos);<br>
+#else<br>
+  // No known technique for statically extracting a type name on this compiler.<br>
+  // We return a string that is unlikely to look like any type in LLVM.<br>
+  return "UNKNOWN_TYPE";<br>
+#endif<br>
+}<br>
+<br>
+}<br>
+<br>
+#endif<br>
<br>
Modified: llvm/trunk/unittests/Support/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=261819&r1=261818&r2=261819&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=261819&r1=261818&r2=261819&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/Support/CMakeLists.txt (original)<br>
+++ llvm/trunk/unittests/Support/CMakeLists.txt Wed Feb 24 21:58:21 2016<br>
@@ -42,6 +42,7 @@ add_llvm_unittest(SupportTests<br>
   ThreadPool.cpp<br>
   TimerTest.cpp<br>
   TimeValueTest.cpp<br>
+  TypeNameTest.cpp<br>
   TrailingObjectsTest.cpp<br>
   UnicodeTest.cpp<br>
   YAMLIOTest.cpp<br>
<br>
Added: llvm/trunk/unittests/Support/TypeNameTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/TypeNameTest.cpp?rev=261819&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/TypeNameTest.cpp?rev=261819&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/Support/TypeNameTest.cpp (added)<br>
+++ llvm/trunk/unittests/Support/TypeNameTest.cpp Wed Feb 24 21:58:21 2016<br>
@@ -0,0 +1,49 @@<br>
+//===- TypeNameTest.cpp ---------------------------------------------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/Support/TypeName.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+#include "gtest/gtest.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+namespace {<br>
+namespace N1 {<br>
+struct S1 {};<br>
+class C1 {};<br>
+union U1 {};<br>
+}<br>
+<br>
+TEST(TypeNameTest, Names) {<br>
+  struct S2 {};<br>
+<br>
+  StringRef S1Name = getTypeName<N1::S1>();<br>
+  StringRef C1Name = getTypeName<N1::C1>();<br>
+  StringRef U1Name = getTypeName<N1::U1>();<br>
+  StringRef S2Name = getTypeName<S2>();<br>
+<br>
+#if defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER) ||    \<br>
+    defined(_MSC_VER)<br>
+  EXPECT_TRUE(S1Name.endswith("::N1::S1")) << S1Name.str();<br>
+  EXPECT_TRUE(C1Name.endswith("::N1::C1")) << C1Name.str();<br>
+  EXPECT_TRUE(U1Name.endswith("::N1::U1")) << U1Name.str();<br>
+#ifdef __clang__<br>
+  EXPECT_TRUE(S2Name.endswith("S2")) << S2Name.str();<br>
+#else<br>
+  EXPECT_TRUE(S2Name.endswith("::S2")) << S2Name.str();<br>
+#endif<br>
+#else<br>
+  EXPECT_EQ("UNKNOWN_TYPE", S1Name);<br>
+  EXPECT_EQ("UNKNOWN_TYPE", C1Name);<br>
+  EXPECT_EQ("UNKNOWN_TYPE", U1Name);<br>
+  EXPECT_EQ("UNKNOWN_TYPE", S2Name);<br>
+#endif<br>
+}<br>
+<br>
+} // end anonymous namespace<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</body>
</html>