[llvm] r292467 - llvm-cxxfilt: filter out invalid manglings

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 19 15:55:07 PST 2017


Sounds good to me. Go ahead and merge (or let me know if you'd like me
to do it).

On Thu, Jan 19, 2017 at 2:12 PM, Saleem Abdulrasool
<compnerd at compnerd.org> wrote:
> Hi Hans,
>
> Would it be possible to merge this into the release branch as well?  It only
> impacts the tool and corrects the behavior so I believe it to be low impact.
>
> On Wed, Jan 18, 2017 at 7:09 PM Saleem Abdulrasool via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: compnerd
>>
>> Date: Wed Jan 18 20:58:46 2017
>>
>> New Revision: 292467
>>
>>
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=292467&view=rev
>>
>> Log:
>>
>> llvm-cxxfilt: filter out invalid manglings
>>
>>
>>
>> c++filt does not attempt to demangle symbols which do not match its
>>
>> expected format.  This means that the symbol must start with _Z or ___Z
>>
>> (block invocation function extension).  Any other symbols are returned
>>
>> as is.  Note that this is different from the behaviour of __cxa_demangle
>>
>> which will demangle fragments.
>>
>>
>>
>> Added:
>>
>>     llvm/trunk/test/tools/llvm-cxxfilt/invalid.test
>>
>> Modified:
>>
>>     llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
>>
>>
>>
>> Added: llvm/trunk/test/tools/llvm-cxxfilt/invalid.test
>>
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cxxfilt/invalid.test?rev=292467&view=auto
>>
>>
>> ==============================================================================
>>
>> --- llvm/trunk/test/tools/llvm-cxxfilt/invalid.test (added)
>>
>> +++ llvm/trunk/test/tools/llvm-cxxfilt/invalid.test Wed Jan 18 20:58:46
>> 2017
>>
>> @@ -0,0 +1,6 @@
>>
>> +RUN: llvm-cxxfilt _Z1fi __Z1fi f ___ZSt1ff_block_invoke | FileCheck %s
>>
>> +
>>
>> +CHECK: f(int)
>>
>> +CHECK-NEXT: __Z1fi
>>
>> +CHECK-NEXT: f
>>
>> +CHECK-NEXT: invocation function for block in std::f(float)
>>
>>
>>
>> Modified: llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
>>
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp?rev=292467&r1=292466&r2=292467&view=diff
>>
>>
>> ==============================================================================
>>
>> --- llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp (original)
>>
>> +++ llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp Wed Jan 18 20:58:46
>> 2017
>>
>> @@ -14,9 +14,12 @@
>>
>>
>>
>>  using namespace llvm;
>>
>>
>>
>> -static void demangle(llvm::raw_ostream &OS, const char *Mangled) {
>>
>> +static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
>>
>>    int Status;
>>
>> -  char *Demangled = itaniumDemangle(Mangled, nullptr, nullptr, &Status);
>>
>> +  char *Demangled = nullptr;
>>
>> +  if ((Mangled.size() >= 2 && Mangled.compare(0, 2, "_Z")) ||
>>
>> +      (Mangled.size() >= 4 && Mangled.compare(0, 4, "___Z")))
>>
>> +    Demangled = itaniumDemangle(Mangled.c_str(), nullptr, nullptr,
>> &Status);
>>
>>    OS << (Demangled ? Demangled : Mangled) << '\n';
>>
>>    free(Demangled);
>>
>>  }
>>
>> @@ -24,7 +27,7 @@ static void demangle(llvm::raw_ostream &
>>
>>  int main(int argc, char **argv) {
>>
>>    if (argc == 1)
>>
>>      for (std::string Mangled; std::getline(std::cin, Mangled);)
>>
>> -      demangle(llvm::outs(), Mangled.c_str());
>>
>> +      demangle(llvm::outs(), Mangled);
>>
>>    else
>>
>>      for (int I = 1; I < argc; ++I)
>>
>>        demangle(llvm::outs(), argv[I]);
>>
>>
>>
>>
>>
>> _______________________________________________
>>
>> llvm-commits mailing list
>>
>> llvm-commits at lists.llvm.org
>>
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>


More information about the llvm-commits mailing list