-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules #104512
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
dmpolukhin
merged 12 commits into
llvm:main
from
dmpolukhin:assert-not-instantiated-in-scope-cxx-modules
Sep 10, 2024
Merged
[RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules #104512
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8772795
[RFC][C++20][Modules] Fix crash when function and lambda inside loade…
dmpolukhin 524344e
[RFC][C++20][Modules] Fix crash when function and lambda inside loade…
dmpolukhin f5606eb
Try different approach withreverse order of loading specializations
dmpolukhin 11b798d
Fix clang-format issue
dmpolukhin 1fc4693
Visit lambdas right after FunctionDecl
dmpolukhin 64230ad
Fix a warning for -Wcovered-switch-default (#105054)
kyulee-com 4a964a7
Add minimal reroducer for the crash after changing deserialization order
dmpolukhin 01375e3
Fix a warning for -Wcovered-switch-default (#105054)
kyulee-com 2b588e5
[flang][cuda] Add missing dependency (#106298)
clementval db65f69
Fix a warning for -Wcovered-switch-default (#105054)
kyulee-com b5f6a30
Delay loading lambdas
dmpolukhin bd6386f
Comments resolved
dmpolukhin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
clang/test/Headers/crash-instantiated-in-scope-cxx-modules.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// RUN: rm -fR %t | ||
// RUN: split-file %s %t | ||
// RUN: cd %t | ||
// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header -Werror=uninitialized folly-conv.h | ||
// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header -Werror=uninitialized thrift_cpp2_base.h | ||
// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header -Werror=uninitialized -fmodule-file=folly-conv.pcm -fmodule-file=thrift_cpp2_base.pcm logger_base.h | ||
|
||
//--- Conv.h | ||
#pragma once | ||
|
||
template <typename _Tp, typename _Up = _Tp&&> | ||
_Up __declval(int); | ||
|
||
template <typename _Tp> | ||
auto declval() noexcept -> decltype(__declval<_Tp>(0)); | ||
|
||
namespace folly { | ||
|
||
template <class Value, class Error> | ||
struct Expected { | ||
template <class Yes> | ||
auto thenOrThrow() -> decltype(declval<Value&>()) { | ||
return 1; | ||
} | ||
}; | ||
|
||
struct ExpectedHelper { | ||
template <class Error, class T> | ||
static constexpr Expected<T, Error> return_(T) { | ||
return Expected<T, Error>(); | ||
} | ||
|
||
template <class This, class Fn, class E = int, class T = ExpectedHelper> | ||
static auto then_(This&&, Fn&&) | ||
-> decltype(T::template return_<E>((declval<Fn>()(true), 0))) { | ||
return Expected<int, int>(); | ||
} | ||
}; | ||
|
||
template <class Tgt> | ||
inline Expected<Tgt, const char*> tryTo() { | ||
Tgt result = 0; | ||
// In build with asserts: | ||
// clang/lib/Sema/SemaTemplateInstantiate.cpp: llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *clang::LocalInstantiationScope::findInstantiationOf(const Decl *): Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this scope"' failed. | ||
// In release build compilation error on the line below inside lambda: | ||
// error: variable 'result' is uninitialized when used here [-Werror,-Wuninitialized] | ||
ExpectedHelper::then_(Expected<bool, int>(), [&](bool) { return result; }); | ||
return {}; | ||
} | ||
|
||
} // namespace folly | ||
|
||
inline void bar() { | ||
folly::tryTo<int>(); | ||
} | ||
// expected-no-diagnostics | ||
|
||
//--- folly-conv.h | ||
#pragma once | ||
#include "Conv.h" | ||
// expected-no-diagnostics | ||
|
||
//--- thrift_cpp2_base.h | ||
#pragma once | ||
#include "Conv.h" | ||
// expected-no-diagnostics | ||
|
||
//--- logger_base.h | ||
#pragma once | ||
import "folly-conv.h"; | ||
import "thrift_cpp2_base.h"; | ||
|
||
inline void foo() { | ||
folly::tryTo<unsigned>(); | ||
} | ||
// expected-no-diagnostics |
30 changes: 30 additions & 0 deletions
30
clang/test/Headers/crash-instantiated-in-scope-cxx-modules2.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// RUN: rm -fR %t | ||
// RUN: split-file %s %t | ||
// RUN: cd %t | ||
// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header header.h | ||
// RUN: %clang_cc1 -std=c++20 -fmodule-file=header.pcm main.cpp | ||
|
||
//--- header.h | ||
template <typename T> | ||
void f(T) {} | ||
|
||
class A { | ||
virtual ~A(); | ||
}; | ||
|
||
inline A::~A() { | ||
f([](){}); | ||
} | ||
|
||
struct B { | ||
void g() { | ||
f([](){ | ||
[](){}; | ||
}); | ||
} | ||
}; | ||
// expected-no-diagnostics | ||
|
||
//--- main.cpp | ||
import "header.h"; | ||
// expected-no-diagnostics |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is not paired with writing process. It will only write a zero if it is not the first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChuanqiXu9 could you please elaborate why you think it may not be paired? Code in ASTDeclWriter looks like this:
So in the first case it writes size + following decls, in the second case it writes 0. I looked the implementation of skipInts for
skipInts(0)
it does nothing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it was an oversight. I took too quickly from the above stack trace.