This is an archive of the discontinued LLVM Phabricator instance.

[Indexing] Fixing inconsistencies between FUNCDNAME and generated code by improving ASTContext's API for MangleContext
Needs ReviewPublic

Authored by pacxx on Feb 21 2018, 1:11 AM.

Details

Summary

The MangleContext API from ASTContext is used incorrectly in the handling of the FUNCDNAME resulting in inconsistencies between the results of FUNCDNAME and the mangled function names in CodeGen.

This fix simplifies the ASTContext API so that it owns the mangling context what removes the inconsistencies.

Diff Detail

Event Timeline

pacxx created this revision.Feb 21 2018, 1:11 AM
rnk added a comment.Feb 21 2018, 5:53 PM

Can you update the description to clarify that this is fixing a bug in the indexing library? From the description it sounds like we have a serious bug in FUNCDNAME codegen, which is not the case. CodeGen does the right thing. The ASTContext API is just crappy, so the Index library used it incorrectly. The fix is to simplify the ASTContext API so that it owns the mangling context.

include/clang/AST/ASTContext.h
2161–2163

Please refactor all the other code that uses createMangleContext to use getMangleContext, and then make createMangleContext private.

pacxx planned changes to this revision.Feb 22 2018, 12:54 AM
pacxx updated this revision to Diff 135372.Feb 22 2018, 1:31 AM
pacxx retitled this revision from [NameMangling] Make ASTContext owning the ManglingContext during entire compilation to [Indexing] Fixing inconsistencies between FUNCDNAME and generated code by improving ASTContext's API for MangleContext.
pacxx edited the summary of this revision. (Show Details)

Refactored as suggested.

Code looks good, but we should test it. Can you add a CodeGenCXX test that shows the issue with FUNCDNAME? I see the issue with this program:

#include <stdio.h>
int main() {
  const char *s1 = ([]() { return __FUNCDNAME__; })();
  const char *s2 = ([]() { return __FUNCDNAME__; })();
  printf("%s\n%s\n", s1, s2);
}
lib/AST/Expr.cpp
500–502

Oh, I see, FUNCDNAME was really broken. Ignore my previous comment.