[llvm] r286795 - Demangle: only demangle mangled symbols
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 13 20:54:47 PST 2016
Author: compnerd
Date: Sun Nov 13 22:54:47 2016
New Revision: 286795
URL: http://llvm.org/viewvc/llvm-project?rev=286795&view=rev
Log:
Demangle: only demangle mangled symbols
Only attempt to demangle symbols which have the itanium C++ prefix of `_Z`.
This ensures that we do not treat any symbol name as a managled named. We would
previously treat a C function `f` as a mangled name and decode that to `float`
incorrectly.
While it is easy to add tests for this, Mehdi recommended against introducing
tests for the demangler as libc++abi should cover the testing.
Modified:
llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
Modified: llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Demangle/ItaniumDemangle.cpp?rev=286795&r1=286794&r2=286795&view=diff
==============================================================================
--- llvm/trunk/lib/Demangle/ItaniumDemangle.cpp (original)
+++ llvm/trunk/lib/Demangle/ItaniumDemangle.cpp Sun Nov 13 22:54:47 2016
@@ -4252,6 +4252,16 @@ char *llvm::itaniumDemangle(const char *
*status = invalid_args;
return nullptr;
}
+
+ size_t len = std::strlen(mangled_name);
+ if (len < 2 || strncmp(mangled_name, "_Z", 2)) {
+ if (len < 4 || strncmp(mangled_name, "___Z", 4)) {
+ if (status)
+ *status = invalid_mangled_name;
+ return nullptr;
+ }
+ }
+
size_t internal_size = buf != nullptr ? *n : 0;
Db db;
db.cv = 0;
@@ -4263,7 +4273,6 @@ char *llvm::itaniumDemangle(const char *
db.fix_forward_references = false;
db.try_to_parse_template_args = true;
int internal_status = success;
- size_t len = std::strlen(mangled_name);
demangle(mangled_name, mangled_name + len, db, internal_status);
if (internal_status == success && db.fix_forward_references &&
!db.template_param.empty() && !db.template_param.front().empty()) {
More information about the llvm-commits
mailing list