[llvm] r272767 - Speculative buildbot fix.

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 08:01:12 PDT 2016


MSVC 2015 was able to build it with a friend function definition. See
attached patch. No implied warranty, you should probably test it with GCC
first. :)

On Wed, Jun 15, 2016 at 2:17 AM, Sean Silva via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> A small example of the issue here is:
>
> ```
> namespace foo {
> class Foo {
>   class Contained {
>     int x;
>   };
>
>   friend void bar(Foo::Contained &);
> };
> // Is this needed? GCC and ICC think so. Clang disagrees.
> //void bar(Foo::Contained &);
> }
>
> void foo::bar(Foo::Contained &) {
> }
> ```
>
> Testing a couple compilers at https://godbolt.org/g/kNmQhB it seems like
> clang does not need the extra declaration inside the namespace but gcc and
> icc do.
>
> I think it is this question also:
> http://stackoverflow.com/questions/16718166/friend-function-declaration-definition-inside-a-namespace
>
> -- Sean Silva
>
> On Wed, Jun 15, 2016 at 2:00 AM, Sean Silva via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: silvas
>> Date: Wed Jun 15 04:00:33 2016
>> New Revision: 272767
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=272767&view=rev
>> Log:
>> Speculative buildbot fix.
>>
>> This wasn't failing for me with clang as the compiler. I think GCC may
>> disagree with clang about whether a friend declaration introduces a
>> declaration in the enclosing namespace (or something).
>>
>> Example error:
>>
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:950:77:
>> error: ‘llvm::raw_ostream&
>> llvm::slpvectorizer::operator<<(llvm::raw_ostream&, const
>> llvm::slpvectorizer::BoUpSLP::ScheduleData&)’ should have been declared
>> inside ‘llvm::slpvectorizer’
>>                                               const BoUpSLP::ScheduleData
>> &SD) {
>>
>>    ^
>>
>> Modified:
>>     llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
>>
>> Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=272767&r1=272766&r2=272767&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Wed Jun 15
>> 04:00:33 2016
>> @@ -942,6 +942,11 @@ private:
>>    /// can legally be represented.
>>    MapVector<Value *, uint64_t> MinBWs;
>>  };
>> +
>> +#ifndef NDEBUG
>> +raw_ostream &operator<<(raw_ostream &os, const BoUpSLP::ScheduleData
>> &SD);
>> +#endif
>> +
>>  } // end namespace llvm
>>  } // end namespace slpvectorizer
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160615/401edb82/attachment.html>
-------------- next part --------------
diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp
index ca40bff..774650b 100644
--- a/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -601,7 +601,6 @@ private:
   /// A list of blocks that we are going to CSE.
   SetVector<BasicBlock *> CSEBlocks;
 
-public: // Workaround for MSVC friend semantics.
   /// Contains all scheduling relevant data for an instruction.
   /// A ScheduleData either represents a single instruction or a member of an
   /// instruction bundle (= a group of instructions which is combined into a
@@ -731,11 +730,13 @@ public: // Workaround for MSVC friend semantics.
     /// dry-run).
     bool IsScheduled;
   };
-private:
 
 #ifndef NDEBUG
-  friend raw_ostream &operator<<(raw_ostream &os,
-                                 const BoUpSLP::ScheduleData &SD);
+  friend inline raw_ostream &operator<<(raw_ostream &os,
+                                        const BoUpSLP::ScheduleData &SD) {
+    SD.dump(os);
+    return os;
+  }
 #endif
 
   /// Contains all scheduling data for a basic block.
@@ -945,21 +946,9 @@ private:
   MapVector<Value *, uint64_t> MinBWs;
 };
 
-#ifndef NDEBUG
-raw_ostream &operator<<(raw_ostream &os, const BoUpSLP::ScheduleData &SD);
-#endif
-
 } // end namespace llvm
 } // end namespace slpvectorizer
 
-#ifndef NDEBUG
-raw_ostream &llvm::slpvectorizer::operator<<(raw_ostream &os,
-                                             const BoUpSLP::ScheduleData &SD) {
-  SD.dump(os);
-  return os;
-}
-#endif
-
 void BoUpSLP::buildTree(ArrayRef<Value *> Roots,
                         ArrayRef<Value *> UserIgnoreLst) {
   deleteTree();


More information about the llvm-commits mailing list