summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Demangle/MicrosoftDemangle.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [MS Demangler] Demangle member pointer template parameters.Zachary Turner2018-08-201-49/+144
| | | | llvm-svn: 340199
* [MS Demangler] Resolve backreferences eagerly, not lazily.Zachary Turner2018-08-181-115/+91
| | | | | | | | | | | | | | | | | | | | A while back I submitted a patch to resolve backreferences lazily, thinking this that it was not always possible to know in advance what type you were looking at until you had completed a full pass over the input, and therefore it would be impossible to resolve backreferences eagerly. This was mistaken though, and turned out to be an unrelated problem. In fact, the reverse is true. You *must* resolve backreferences eagerly. This is because certain types of nested mangled symbols do not share a backreference context with their parent symbol, and as such, if you try to resolve them lazily their backreference context will have been lost by the time you finish demangling the entire input. On the other hand, resolving them eagerly appears to always work, and enables us to port many more tests over. llvm-svn: 340126
* [MS Demangler] Properly print all thunk types.Zachary Turner2018-08-171-4/+11
| | | | | | | | | We were only printing the vtordisp thunk before as the previous patch was more aimed at getting special operators working, one of which was a thunk. This patch gets all thunk types to print properly, and adds a test for each one. llvm-svn: 340088
* [MS Demangler] Demangle all remaining types of operators.Zachary Turner2018-08-171-123/+401
| | | | | | | This demangles all remaining special operators including thunks, RTTI Descriptors, and local static guard variables. llvm-svn: 340083
* [MS Demangler] Rework the way operators are demangled.Zachary Turner2018-08-171-221/+323
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, some of the code for actually parsing mangled operator names was more like formatting code in nature, and was interspersed with the demangling code which builds the AST. This means that by the time we got to the printing code, we had lost all information about what type of operator we had, and all we were left with was a string that we just had to print. However, not all operators are actually even operators. it's basically just a catch-all mangling for "special names", and for some of the other types it helps to know when we're actually doing the printing what it is. This patch changes the way things work by introducing an OperatorInfo structure and corresponding enumeration. When we demangle we store the enumeration value and demangled components separately. This gives more flexibility during printing. In doing so, some demanglings of special names which we didn't previously support come out of this for free, so we now demangle those. A few are more complex and are better left for a followup patch though. An exhaustive test of every possible operator code is included, with the ones that don't yet work commented out. llvm-svn: 340046
* Fix memory leak in demangling of string literals.Zachary Turner2018-08-161-0/+1
| | | | llvm-svn: 339909
* Fix -Wmicrosoft-goto warnings.Zachary Turner2018-08-161-7/+13
| | | | llvm-svn: 339894
* [MS Demangler] Demangle string literals.Zachary Turner2018-08-161-3/+398
| | | | | | | | | | | | | | | | | | | | When demangling string literals, Microsoft's undname simply prints 'string'. This patch implements string literal demangling while doing a bit better than this by decoding as much of the string as possible and trying to faithfully reproduce the original string literal definition. This is a bit tricky because the different character types char, char16_t, and char32_t are not uniquely identified by the mangling, so we have to use a heuristic to try to guess the character type. But it works pretty well, and many tests are added to illustrate the behavior. Differential Revision: https://reviews.llvm.org/D50806 llvm-svn: 339892
* [MS Demangler] Don't fail on MD5-mangled names.Zachary Turner2018-08-161-1/+14
| | | | | | | | When we have an MD5 mangled name, we shouldn't choke and say that it's an invalid name. Even though it's impossible to demangle, we should just output the original name. llvm-svn: 339891
* [MS Demangler] Fix some minor formatting bugs.Zachary Turner2018-08-141-7/+5
| | | | | | | | | | | | | | | | 1) We print __restrict twice on member pointers. This is fixed and relevant tests are re-enabled. 2) Several tests were disabled because of printing slightly different output than undname. These were confirmed to be bugs in undname, so we just re-enable the tests. 3) The test for printing reference temporaries is re-enabled. This is a clang mangling extension, so we have some flexibility with how we demangle it. The output currently looks fine, so we just re-enable the test with no fixes. llvm-svn: 339708
* [MS Demangler] Support extern "C" functions.Zachary Turner2018-08-101-24/+48
| | | | | | | | | | | | | | There are two cases we need to support with extern "C" functions. The first is the case of a '9' indicating that the function has no prototype. This occurs when we mangle a symbol inside of an extern "C" function, but not the function itself. The second case is when we have an overloaded extern "C" functions. In this case we emit $$J0 to indicate this. This patch adds support for both of these cases. llvm-svn: 339471
* [MS Demangler] Demangle cv qualifiers on template args.Zachary Turner2018-08-101-0/+4
| | | | | | | | | | | | | Before we wouldn't properly demangle something like Foo<const int>. Template args have a special escape sequence '$$C' that is optional, but if it is present contains qualifiers. So we need to check for this and only if it present, demangle qualifiers before demangling the type. With this fix, we re-enable some tests that were previously marked FIXME. llvm-svn: 339465
* [MS Demangler] Properly demangle conversion operators.Zachary Turner2018-08-101-20/+44
| | | | | | | These were completely broken before. We need to handle the 'B' operator tag. llvm-svn: 339436
* [MS Demangler] Fix several issues related to templates.Zachary Turner2018-08-101-34/+90
| | | | | | | | | | | | These were uncovered when porting the mangling tests in ms-templates.cpp from clang/CodeGenCXX over to demangling tests. The main issues fixed here are surrounding integer literal signed and unsignedness, empty array dimensions, and pointer and reference non-type template parameters. Differential Revision: https://reviews.llvm.org/D50512 llvm-svn: 339434
* [MS Demangler] Create a new backref context for template instantiations.Zachary Turner2018-08-081-29/+39
| | | | | | | | Template manglings use a fresh back-referencing context, so we need to do the same. This fixes several existing tests which are marked as FIXME, so those are now actually run. llvm-svn: 339275
* [MS Demangler] Properly handle backreferencing of special names.Zachary Turner2018-08-081-20/+36
| | | | | | | | | | | | | | | | | | | | | Function template names are not stored in the backref table, but non-template function names are. The general pattern seems to be that when you are demangling a symbol name, if the name starts with '?' it does not go into the backreference table, otherwise it does. Note that this even handles the general case of operator names (template or otherwise) not going into the back-reference table, anonymous namespaces not going into the backreference table, etc. It's important that we apply this check *only* for the unqualified portion of a name, and only for symbol names. For example, this does not apply to type names (such as class templates) and we need to make sure that these still do go into the backref table. Differential Revision: https://reviews.llvm.org/D50394 llvm-svn: 339211
* Fix one more warning.Zachary Turner2018-08-021-0/+1
| | | | llvm-svn: 338742
* Fix a couple of warnings.Zachary Turner2018-08-021-1/+2
| | | | llvm-svn: 338739
* Use %.*s instead of %*s when formatting strings with explicit length.Zachary Turner2018-08-021-2/+2
| | | | llvm-svn: 338737
* [MS Demangler] Resolve back-references lazily.Zachary Turner2018-08-021-87/+106
| | | | | | | | | | | We need to both record and resolve back-references lazily due to not being able to know until a demangling is complete whether or not a name should go into the back-reference table.. This patch implements lazy resolution of back-references, but we still have eager recording of back-references. This will be fixed in a subsequent patch. llvm-svn: 338736
* Try to fix FreeBSD build.Zachary Turner2018-08-011-9/+10
| | | | | | | | It seems like perhaps because cstdio isn't directly included, the compiler is accidentally picking up wprintf from somewhere else and trying to call that. Hopefully this fixes it. llvm-svn: 338614
* [llvm-undname Add an option to dump back references.Zachary Turner2018-08-011-1/+34
| | | | | | | | | This is useful for understanding how our demangler processes back references and for investigating issues related to back references. But it's a feature only useful for debugging the demangling process itself, so I'm marking it hidden. llvm-svn: 338609
* [MS Demangler] Properly demangle templated operators.Zachary Turner2018-08-011-31/+43
| | | | | | | | | | | | | | | | | | After we detected the presence of a template via ?$ we would proceed by only demangling a simple unqualified name. This means we would fail on templated operators (and perhaps other yet-to-be-determined things) This was discovered while doing some refactoring to store richer semantic information about the demangled types to pave the way for overhauling the way we handle backreferences. (Specifically, we need to defer recording or resolving back-references until a symbol has been completely demangled, because we need to use information that only occurs later in the mangled string to decide whether a back-reference should be recorded.) Differential Revision: https://reviews.llvm.org/D50145 llvm-svn: 338608
* [MS Demangler] Don't crash as often when demangling.Zachary Turner2018-08-011-10/+28
| | | | | | | We crash a lot on unrecognized inputs. This adds some error handling so we early out when we get unrecognized names. llvm-svn: 338607
* Resubmit r338340 "[MS Demangler] Better demangling of template arguments."Zachary Turner2018-07-311-45/+87
| | | | | | This broke the build with GCC, but has since been fixed. llvm-svn: 338403
* Revert r338340 "[MS Demangler] Better demangling of template arguments."Reid Kleckner2018-07-311-87/+46
| | | | | | Breaks the build with GCC, apparently. llvm-svn: 338344
* [MS Demangler] Better demangling of template arguments.Zachary Turner2018-07-311-46/+87
| | | | | | | | | | | This patch fixes demangling of template aliases as template-template arguments, and also fixes function pointers and references as not type template parameters. All of these can be properly demangled now, so I've ported over the test clang/test/CodeGenCXX/ms-template-callbacks.cpp. All of these tests pass llvm-svn: 338340
* [MS Demangler] Add rudimentary C++11 SupportZachary Turner2018-07-301-48/+173
| | | | | | | | | | | | | | This patch adds support for demangling r-value references, new operators such as the ""_foo operator, lambdas, alias types, nullptr_t, and various other C++11'isms. There is 1 failing test remaining in this file, which appears to be related to back-referencing. This type of problem has the potential to get ugly so I'd rather fix it in a separate patch. Differential Revision: https://reviews.llvm.org/D50013 llvm-svn: 338324
* Try to fix build.Zachary Turner2018-07-301-5/+5
| | | | llvm-svn: 338227
* [MS Demangler] Demangle symbols in function scopes.Zachary Turner2018-07-301-12/+132
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are a couple of issues you run into when you start getting into more complex names, especially with regards to function local statics. When you've got something like: int x() { static int n = 0; return n; } Then this needs to demangle to something like int `int __cdecl x()'::`1'::n The nested mangled symbols (e.g. `int __cdecl x()` in the above example) also share state with regards to back-referencing, so we need to be able to re-use the demangler in the middle of demangling a symbol while sharing back-ref state. To make matters more complicated, there are a lot of ambiguities when demangling a symbol's qualified name, because a function local scope pattern (usually something like `?1??name?`) looks suspiciously like many other possible things that can occur, such as `?1` meaning the second back-ref and disambiguating these cases is rather interesting. The `?1?` in a local scope pattern is actually a special case of the more general pattern of `? + <encoded number> + ?`, where "encoded number" can itself have embedded `@` symbols, which is a common delimeter in mangled names. So we have to take care during the disambiguation, which is the reason for the overly complicated `isLocalScopePattern` function in this patch. I've added some pretty obnoxious tests to exercise all of this, which exposed several other problems related to back-referencing, so those are fixed here as well. Finally, I've uncommented some tests that were previously marked as `FIXME`, since now these work. Differential Revision: https://reviews.llvm.org/D49965 llvm-svn: 338226
* [MS Demangler] NFC - Remove state from Demangler class.Zachary Turner2018-07-291-152/+152
| | | | | | | | | | | We need to be able to initiate a nested demangling from inside of an "outer" demangling. These need to be able to share some state, such as back-references. As a result, we can't store things like the output stream or the mangled name in the Demangler class, since each demangling will have different values. So remove this state and pass it through the necessary methods. llvm-svn: 338219
* [MS Demangler] Refactor some of the name parsing code.Zachary Turner2018-07-281-181/+246
| | | | | | | | | | | | | | There are some very subtle differences between how one should parse symbol names and type names. They differ with respect to back-referencing, the set of legal values that can appear as the unqualified portion, and various other aspects. By separating the parsing code into separate paths, we can remove a lot of ambiguity during the demangling process, which is necessary for demangling more complicated things like function local statics, nested classes, and lambdas. llvm-svn: 338207
* Fix -Wsign-compare warning.Zachary Turner2018-07-261-1/+1
| | | | llvm-svn: 338078
* [MS Demangler] Properly handle function parameter back-refs.Zachary Turner2018-07-261-17/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Properly demangle function parameter back-references. Previously we treated lists of function parameters and template parameters the same. There are some important differences with regards to back-references, and some less important differences regarding which characters can appear before or after the name. The important differences are that with a given type T, all instances of a function parameter list share the same global back-ref table. Specifically, if X and Y are function pointers, then there are 3 entities in the declaration X func(Y) which all affect and are affected by the master parameter back-ref table: 1) The parameter list of X's function type 2) the parameter list of func itself 3) The parameter list of Y's function type. The previous code would create a back-reference table that was local to a single parameter list, so it would not be shared across parameter lists. This was discovered when porting ms-back-references.test from clang's mangling tests. All of these tests should now pass with the new changes. In doing so, I split the function for parsing template and function parameters into two separate functions. This makes the template parameter list parsing code in particular very small and easy to understand now. Differential Revision: https://reviews.llvm.org/D49875 llvm-svn: 338075
* [MS Demangler] Print calling convention inside parentheses.Zachary Turner2018-07-261-35/+48
| | | | | | | | | | | | | | | For function pointers, we would print something like int __cdecl (*)(int) We need to move the calling convention inside, and print int (__cdecl *)(int) This patch implements this change for regular function pointers as well as member function pointers. llvm-svn: 338068
* [MS Demangler] Add ms-arg-qualifiers.testZachary Turner2018-07-261-2/+5
| | | | | | | | | | | This converts the arg qualifier mangling tests from clang/CodeGenCXX/mangle-ms-arg-qualifiers.cpp to demangling tests. Most tests already pass, so this patch doesn't come with any functional change, just the addition of new tests. The few tests that don't pass are left in with a FIXME label so that they don't run but serve as documentation about what still doesn't work. llvm-svn: 338067
* [MS Demangler] Demangle pointers to member functions.Zachary Turner2018-07-261-45/+91
| | | | | | | | | | | After this patch, we can now properly demangle pointers to member functions. The calling convention is located in the wrong place, but this will be fixed in a followup since it also affects non member function pointers. Differential Revision: https://reviews.llvm.org/D49639 llvm-svn: 338065
* [MS Demangler] Demangle data member pointers.Zachary Turner2018-07-261-155/+191
| | | | | | Differential Revision: https://reviews.llvm.org/D49630 llvm-svn: 338061
* [Demangle] Attempt to fix arena memory leakReid Kleckner2018-07-231-1/+3
| | | | llvm-svn: 337720
* Remove a superfluous semicolonMartin Storsjo2018-07-201-1/+1
| | | | llvm-svn: 337599
* [Demangler] Correctly factor in assignment when allocating.Zachary Turner2018-07-201-24/+29
| | | | | | | | | Incidentally all allocations that we currently perform were properly aligned, but this was only an accident. Thanks to Erik Pilkington for catching this. llvm-svn: 337596
* [Demangler] Add missing overridesBenjamin Kramer2018-07-201-3/+3
| | | | | | -Winconsistent-missing-override complains about this. llvm-svn: 337592
* Fix a few warnings and style issues in MS demangler.Zachary Turner2018-07-201-17/+24
| | | | | | Also remove a broken test case. llvm-svn: 337591
* Add a Microsoft Demangler.Zachary Turner2018-07-201-0/+1533
This adds initial support for a demangling library (LLVMDemangle) and tool (llvm-undname) for demangling Microsoft names. This doesn't cover 100% of cases and there are some known limitations which I intend to address in followup patches, at least until such time that we have (near) 100% test coverage matching up with all of the test cases in clang/test/CodeGenCXX/mangle-ms-*. Differential Revision: https://reviews.llvm.org/D49552 llvm-svn: 337584
OpenPOWER on IntegriCloud