[PATCH] D52301: [clang] Set TypeSourceInfo for vardecl's in addition to type when we can deduce.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 16 16:19:32 PDT 2018


kadircet added a comment.

In https://reviews.llvm.org/D52301#1263275, @aaron.ballman wrote:

> Can you give a bit more background on what problem you're trying to solve with this patch?


Sorry for the lack of context, it was about an offline discussion on `Sema::DeduceVariableDeclarationType` just setting the type and not setting the typesourceinfo, which was resulting in having `DeducedType` in type but not in typesourceinfo.

We wanted to fix that behavior because it was resulting in getting "auto"s when we look at typesourceinfo(which happens in astprinter). But then it turned out to be there are other parts of clang(including extra tools) that depend on typesourceinfo not having the deduced type, for example include-fixer and refactoring/rename, relied on that information being missing when they were looking for (usage counts/locations) of symbols they were looking for.

So in the middle of the patch we were just trying to figure out whether we are going to break a big assumption that lots of different components relied on but just didn't had any tests for. Maybe @rsmith would have more context about the behavior?



================
Comment at: lib/Sema/SemaChecking.cpp:852
 
-  if (RT->getPointeeType().getAddressSpace() != LangAS::opencl_generic) {
-    S.Diag(Call->getArg(0)->getBeginLoc(),
----------------
aaron.ballman wrote:
> I'm not certain I understand why this code has been removed?
It shouldn't have been, tried rebasing but it didn't go away. I think it was deleted at some point by a different change and somehow ended up showing in here as well. (Tried to revert, got an error stating warn_opencl_generic_address_space_arg doesn't exist)


================
Comment at: lib/Sema/SemaDecl.cpp:10766
 
-QualType Sema::deduceVarTypeFromInitializer(VarDecl *VDecl,
+std::pair<QualType, TypeSourceInfo*> Sema::deduceVarTypeFromInitializer(VarDecl *VDecl,
                                             DeclarationName Name, QualType Type,
----------------
aaron.ballman wrote:
> Why does this need to return a pair? It seems like the returned `TypeSourceInfo*` carries all the information needed by the caller, or is there ever a case where the `QualType` will be different than what is returned by `TypeSourceInfo::getType()`?
Yes, unfortunately there are cases these two differ. That's exactly the case we are trying to fix with that patch. 


Repository:
  rC Clang

https://reviews.llvm.org/D52301





More information about the cfe-commits mailing list