This is an archive of the discontinued LLVM Phabricator instance.

Change __auto_type behavior with qualifiers to match GCC behavior
ClosedPublic

Authored by aaron.ballman on Mar 18 2022, 12:58 PM.

Details

Summary

Currently, Clang handles some qualifiers correctly for __auto_type, but it does not handle the restrict or _Atomic qualifiers in the same way that GCC does. This patch handles those qualifiers so that they attach to the deduced type the same as const and volatile already do.

This fixes https://github.com/llvm/llvm-project/issues/53652

Diff Detail

Event Timeline

aaron.ballman created this revision.Mar 18 2022, 12:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2022, 12:58 PM
aaron.ballman requested review of this revision.Mar 18 2022, 12:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2022, 12:58 PM

Just a couple of questions/concerns! Otherwise it LGTM. Since I have a suggestion for a code change, I'll hold off on approval until you do it or give a reasonable reason why not.

clang/lib/AST/ASTContext.cpp
10290

So do we care if BOTH sides are this auto type? Further question: can there be more than 1 of these 'GNUAutoType's in the type system such that 10211 wouldn't fire?

Also, slight preference for AutoType having 'isGNUAutoTYpe' on it instead of this dance everywhere.

Speaking of which: that also makes me concerned about all the places in our code that assume !isDeclTypeAuto means C++ auto.... But that is perhaps for a future bug reporter to discover.

Updated based on review feedback.

clang/lib/AST/ASTContext.cpp
10290

So do we care if BOTH sides are this auto type?

This only fires when the type classes don't match, see 10272.

Further question: can there be more than 1 of these 'GNUAutoType's in the type system such that 10211 wouldn't fire?

Yes, but we wouldn't hit this block of code in that case because the type classes would match.

Also, slight preference for AutoType having 'isGNUAutoTYpe' on it instead of this dance everywhere.

I was on the fence about that, and this gets me off the fence.

Speaking of which: that also makes me concerned about all the places in our code that assume !isDeclTypeAuto means C++ auto.... But that is perhaps for a future bug reporter to discover.

+1

erichkeane added inline comments.Mar 21 2022, 6:21 AM
clang/lib/Sema/SemaType.cpp
1929

The RHS here should NEVER be true. I think the entirety of the change in this branch other than the 'if' condition needs to be reverted.

xbolva00 added inline comments.
clang/lib/AST/ASTContext.cpp
10294

Same?

erichkeane added inline comments.Mar 21 2022, 6:49 AM
clang/lib/AST/ASTContext.cpp
10294

Oooh, good catch! Looks like it should be RHS->getAs

aaron.ballman marked 2 inline comments as done.

Updated based on review feedback.

erichkeane accepted this revision.Mar 21 2022, 7:26 AM
This revision is now accepted and ready to land.Mar 21 2022, 7:26 AM
aaron.ballman added inline comments.Mar 21 2022, 10:02 AM
clang/lib/AST/ASTContext.cpp
10294

Great catch -- I've fixed and added additional test coverage for it.

FWIW, I plan to land this sometime tomorrow (Mar 23) unless there are additional review comments before then.

Thanks for the reviews, I've committed in e4a42c5b64d044ae28d9483b0ebd12038d5b5917.