Skip to content

[clang] Use getDefaultArgRange instead of getDefaultArg to retrieve the #79296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

hokein
Copy link
Collaborator

@hokein hokein commented Jan 24, 2024

source location in AliasTemplateDeductionGuideTransform.

I don't have a reproducible testcase, but this should be a safe and non-functional change. We have checked the hasDefaultArg before calling getDefaultArg(), but hasDefaultArg allows unparsed/uninstantiated default arg which is prohibited in getDefaultArg().

Since we're only interested in the source location, we switch to use getDefaultArgRange() API.

source location in AliasTemplateDeductionGuideTransform.

I don't have a reproducible testcase, but this should be a safe and non-functional change.
We have checked the `hasDefaultArg` before calling getDefaultArg(), but `hasDefaultArg`
allows unparsed/uninstantiated default arg which is prohibited in getDefaultArg().

Since we're only interested in the source location, we switch to use getDefaultArgRange() API.

Context: I hit the "!hasUninstantiatedDefaultArg()" assertion inside the
getDefaultArg when reusing the "transformFunctionTypeParam" for
implementing type alias CTAD.
@hokein hokein requested a review from sam-mccall January 24, 2024 14:38
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 24, 2024

@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)

Changes

source location in AliasTemplateDeductionGuideTransform.

I don't have a reproducible testcase, but this should be a safe and non-functional change. We have checked the hasDefaultArg before calling getDefaultArg(), but hasDefaultArg allows unparsed/uninstantiated default arg which is prohibited in getDefaultArg().

Since we're only interested in the source location, we switch to use getDefaultArgRange() API.

Context: I hit the "!hasUninstantiatedDefaultArg()" assertion inside the getDefaultArg when reusing the "transformFunctionTypeParam" for type alias CTAD implementation (f091991).


Full diff: https://github.com/llvm/llvm-project/pull/79296.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaTemplate.cpp (+1-1)
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 9bfa71dc8bcf1db..a5d2afdf4a0bab8 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2588,7 +2588,7 @@ struct ConvertConstructorToDeductionGuideTransform {
       // placeholder to indicate there is a default argument.
       QualType ParamTy = NewDI->getType();
       NewDefArg = new (SemaRef.Context)
-          OpaqueValueExpr(OldParam->getDefaultArg()->getBeginLoc(),
+          OpaqueValueExpr(OldParam->getDefaultArgRange().getBegin(),
                           ParamTy.getNonLValueExprType(SemaRef.Context),
                           ParamTy->isLValueReferenceType()   ? VK_LValue
                           : ParamTy->isRValueReferenceType() ? VK_XValue

Copy link
Collaborator

@sam-mccall sam-mccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this!

Would be nice to have a testcase but I see it's hard to get into the crashing state (maybe even not possible via clang).
Seems worthwhile to be robust to such conditions and getDefaultArgRange appears less fragile.

@hokein
Copy link
Collaborator Author

hokein commented Feb 26, 2024

Sorry for missing this!

Would be nice to have a testcase but I see it's hard to get into the crashing state (maybe even not possible via clang). Seems worthwhile to be robust to such conditions and getDefaultArgRange appears less fragile.

This fix was needed for the initial type-alias CTAD implementation, we don't need it anymore in the new implementation :)

We could drop this change, but I think it is worth having it, it is an improvement, and make the code more robust.

@hokein hokein merged commit fec4716 into llvm:main Mar 6, 2024
@hokein hokein deleted the ctad-default-args2 branch March 6, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants