-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Clang crash instantiating lambda with a calling convention specified on it. #58366
Comments
The lambda in InvokeInContext needs to be annotated with __attribute__((stdcall)) for it to work on Clang, but this is blocked on a Clang crash bug: llvm/llvm-project#58366 This reverts commit cc561ec.
Simplified: https://godbolt.org/z/8v16T7PMT template<typename T>
void foo(void *x) {
[](void*x) __attribute__((stdcall)) { return 0;};
}
void bar() {
foo<int>(0);
} |
@llvm/issue-subscribers-clang-frontend |
This is happening during the call to TransformFunctionProtoType in TreeTransform.h's TransformLambdaExpr because the OldCallOpFPTL is actually an |
@MaskRay ended up doing this implementation it looks like, and I'm not completely sure what the exception-specifier stuff is doing, AND |
The lambda in InvokeInContext needs to be annotated with __attribute__((stdcall)) for it to work on Clang, but this is blocked on a Clang crash bug: llvm/llvm-project#58366 This reverts commit cc561ec.
Hi, thanks for looking into this initially. Any chance you can revisit this? I did try to hack this and got something that can compile without crashing, but to be honest I have no idea what is going on here. I am attaching my hack in case it helps... (No lit tests added btw.) Hack patchdiff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index f0d3a5ca089a..1dfb6178e8c9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13128,10 +13128,21 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
// it introduces a mapping of the original to the newly created
// transformed parameters.
TypeSourceInfo *NewCallOpTSI = nullptr;
+ FunctionProtoTypeLoc NewCallOpFPTL;
{
TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
FunctionProtoTypeLoc OldCallOpFPTL =
OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
+ AttributedTypeLoc OldCallOpATTL;
+ bool IsAttributed = false;
+ if (!OldCallOpFPTL) {
+ OldCallOpATTL = OldCallOpTSI->getTypeLoc().getAs<AttributedTypeLoc>();
+ assert(OldCallOpATTL);
+ OldCallOpFPTL =
+ OldCallOpATTL.getModifiedLoc().getAs<FunctionProtoTypeLoc>();
+ assert(OldCallOpFPTL);
+ IsAttributed = true;
+ }
TypeLocBuilder NewCallOpTLBuilder;
SmallVector<QualType, 4> ExceptionStorage;
@@ -13144,8 +13155,36 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
});
if (NewCallOpType.isNull())
return ExprError();
- NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
- NewCallOpType);
+
+ if (IsAttributed) {
+ const AttributedType *oldType = OldCallOpATTL.getTypePtr();
+
+ const Attr *newAttr = getDerived().TransformAttr(OldCallOpATTL.getAttr());
+ if (!newAttr)
+ return ExprError();
+
+ QualType equivalentType =
+ getDerived().TransformType(oldType->getEquivalentType());
+ if (equivalentType.isNull())
+ return ExprError();
+ QualType result = SemaRef.Context.getAttributedType(
+ OldCallOpATTL.getAttrKind(), NewCallOpType, equivalentType);
+
+ AttributedTypeLoc newTL =
+ NewCallOpTLBuilder.push<AttributedTypeLoc>(result);
+ newTL.setAttr(newAttr);
+
+ NewCallOpTSI =
+ NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, result);
+ NewCallOpFPTL = NewCallOpTSI->getTypeLoc()
+ .castAs<AttributedTypeLoc>()
+ .getModifiedLoc()
+ .castAs<FunctionProtoTypeLoc>();
+ } else {
+ NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
+ NewCallOpType);
+ NewCallOpFPTL = NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
+ }
}
// Create the local class that will describe the lambda.
@@ -13179,8 +13218,7 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
// Build the call operator.
CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
Class, E->getIntroducerRange(), NewCallOpTSI,
- E->getCallOperator()->getEndLoc(),
- NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
+ E->getCallOperator()->getEndLoc(), NewCallOpFPTL.getParams(),
E->getCallOperator()->getConstexprKind(),
E->getCallOperator()->getStorageClass(),
E->getCallOperator()->getTrailingRequiresClause());
|
Fixed in trunk (post 17) |
Original code: disconnected-40302b.zip
Toolchain: https://github.com/mstorsjo/llvm-mingw/releases/tag/20220906
Reduced reproducer: https://godbolt.org/z/hM47hEbq8
The text was updated successfully, but these errors were encountered: