Skip to content

Commit a695f67

Browse files
committed
Merge remote-tracking branch 'origin/main' into laa-nonconst-dist-forward
2 parents a9e7fa0 + 5138ccd commit a695f67

File tree

23 files changed

+600
-151
lines changed

23 files changed

+600
-151
lines changed

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,12 @@ class ASTNodeTraverser
851851
Visit(R);
852852
}
853853

854+
void VisitTypeTraitExpr(const TypeTraitExpr *E) {
855+
// Argument types are not children of the TypeTraitExpr.
856+
for (auto *A : E->getArgs())
857+
Visit(A->getType());
858+
}
859+
854860
void VisitLambdaExpr(const LambdaExpr *Node) {
855861
if (Traversal == TK_IgnoreUnlessSpelledInSource) {
856862
for (unsigned I = 0, N = Node->capture_size(); I != N; ++I) {

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,30 @@ bool ByteCodeStmtGen<Emitter>::visitDefaultStmt(const DefaultStmt *S) {
675675

676676
template <class Emitter>
677677
bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) {
678-
// Ignore all attributes.
678+
679+
for (const Attr *A : S->getAttrs()) {
680+
auto *AA = dyn_cast<CXXAssumeAttr>(A);
681+
if (!AA)
682+
continue;
683+
684+
assert(isa<NullStmt>(S->getSubStmt()));
685+
686+
const Expr *Assumption = AA->getAssumption();
687+
if (Assumption->isValueDependent())
688+
return false;
689+
690+
if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
691+
continue;
692+
693+
// Evaluate assumption.
694+
if (!this->visitBool(Assumption))
695+
return false;
696+
697+
if (!this->emitAssume(Assumption))
698+
return false;
699+
}
700+
701+
// Ignore other attributes.
679702
return this->visitStmt(S->getSubStmt());
680703
}
681704

clang/lib/AST/Interp/Interp.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,18 @@ inline bool InvalidDeclRef(InterpState &S, CodePtr OpPC,
23272327
return CheckDeclRef(S, OpPC, DR);
23282328
}
23292329

2330+
inline bool Assume(InterpState &S, CodePtr OpPC) {
2331+
const auto Val = S.Stk.pop<Boolean>();
2332+
2333+
if (Val)
2334+
return true;
2335+
2336+
// Else, diagnose.
2337+
const SourceLocation &Loc = S.Current->getLocation(OpPC);
2338+
S.CCEDiag(Loc, diag::note_constexpr_assumption_failed);
2339+
return false;
2340+
}
2341+
23302342
template <PrimType Name, class T = typename PrimConv<Name>::T>
23312343
inline bool OffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E) {
23322344
llvm::SmallVector<int64_t> ArrayIndices;

clang/lib/AST/Interp/Opcodes.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,8 @@ def InvalidDeclRef : Opcode {
736736
let Args = [ArgDeclRef];
737737
}
738738

739+
def Assume : Opcode;
740+
739741
def ArrayDecay : Opcode;
740742

741743
def CheckNonNullArg : Opcode {

clang/lib/AST/Interp/Program.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,23 @@ Pointer Program::getPtrGlobal(unsigned Idx) const {
108108
}
109109

110110
std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
111-
auto It = GlobalIndices.find(VD);
112-
if (It != GlobalIndices.end())
111+
if (auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
113112
return It->second;
114113

115114
// Find any previous declarations which were already evaluated.
116115
std::optional<unsigned> Index;
117-
for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
118-
auto It = GlobalIndices.find(P);
119-
if (It != GlobalIndices.end()) {
116+
for (const Decl *P = VD->getPreviousDecl(); P; P = P->getPreviousDecl()) {
117+
if (auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
120118
Index = It->second;
121119
break;
122120
}
123121
}
124122

125123
// Map the decl to the existing index.
126-
if (Index) {
124+
if (Index)
127125
GlobalIndices[VD] = *Index;
128-
return std::nullopt;
129-
}
130126

131-
return Index;
127+
return std::nullopt;
132128
}
133129

134130
std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD,
@@ -173,7 +169,6 @@ std::optional<unsigned> Program::getOrCreateDummy(const ValueDecl *VD) {
173169

174170
std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
175171
const Expr *Init) {
176-
assert(!getGlobal(VD));
177172
bool IsStatic, IsExtern;
178173
if (const auto *Var = dyn_cast<VarDecl>(VD)) {
179174
IsStatic = Context::shouldBeGloballyIndexed(VD);

clang/test/AST/Interp/literals.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,4 +1209,16 @@ constexpr int externvar1() { // both-error {{never produces a constant expressio
12091209
namespace Extern {
12101210
constexpr extern char Oops = 1;
12111211
static_assert(Oops == 1, "");
1212+
1213+
#if __cplusplus >= 201402L
1214+
struct NonLiteral {
1215+
NonLiteral() {}
1216+
};
1217+
NonLiteral nl;
1218+
constexpr NonLiteral &ExternNonLiteralVarDecl() {
1219+
extern NonLiteral nl;
1220+
return nl;
1221+
}
1222+
static_assert(&ExternNonLiteralVarDecl() == &nl, "");
1223+
#endif
12121224
}

clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,7 +2725,25 @@ int main()
27252725
// CHECK-NEXT: "type": {
27262726
// CHECK-NEXT: "qualType": "bool"
27272727
// CHECK-NEXT: },
2728-
// CHECK-NEXT: "valueCategory": "prvalue"
2728+
// CHECK-NEXT: "valueCategory": "prvalue",
2729+
// CHECK-NEXT: "inner": [
2730+
// CHECK-NEXT: {
2731+
// CHECK-NEXT: "id": "0x{{.*}}",
2732+
// CHECK-NEXT: "kind": "TemplateTypeParmType",
2733+
// CHECK-NEXT: "type": {
2734+
// CHECK-NEXT: "qualType": "_Ty"
2735+
// CHECK-NEXT: },
2736+
// CHECK-NEXT: "isDependent": true,
2737+
// CHECK-NEXT: "isInstantiationDependent": true,
2738+
// CHECK-NEXT: "depth": 0,
2739+
// CHECK-NEXT: "index": 0,
2740+
// CHECK-NEXT: "decl": {
2741+
// CHECK-NEXT: "id": "0x{{.*}}",
2742+
// CHECK-NEXT: "kind": "TemplateTypeParmDecl",
2743+
// CHECK-NEXT: "name": "_Ty"
2744+
// CHECK-NEXT: }
2745+
// CHECK-NEXT: }
2746+
// CHECK-NEXT: ]
27292747
// CHECK-NEXT: }
27302748
// CHECK-NEXT: ]
27312749
// CHECK-NEXT: }
@@ -3003,7 +3021,25 @@ int main()
30033021
// CHECK-NEXT: "type": {
30043022
// CHECK-NEXT: "qualType": "bool"
30053023
// CHECK-NEXT: },
3006-
// CHECK-NEXT: "valueCategory": "prvalue"
3024+
// CHECK-NEXT: "valueCategory": "prvalue",
3025+
// CHECK-NEXT: "inner": [
3026+
// CHECK-NEXT: {
3027+
// CHECK-NEXT: "id": "0x{{.*}}",
3028+
// CHECK-NEXT: "kind": "TemplateTypeParmType",
3029+
// CHECK-NEXT: "type": {
3030+
// CHECK-NEXT: "qualType": "_Ty"
3031+
// CHECK-NEXT: },
3032+
// CHECK-NEXT: "isDependent": true,
3033+
// CHECK-NEXT: "isInstantiationDependent": true,
3034+
// CHECK-NEXT: "depth": 0,
3035+
// CHECK-NEXT: "index": 0,
3036+
// CHECK-NEXT: "decl": {
3037+
// CHECK-NEXT: "id": "0x{{.*}}",
3038+
// CHECK-NEXT: "kind": "TemplateTypeParmDecl",
3039+
// CHECK-NEXT: "name": "_Ty"
3040+
// CHECK-NEXT: }
3041+
// CHECK-NEXT: }
3042+
// CHECK-NEXT: ]
30073043
// CHECK-NEXT: }
30083044
// CHECK-NEXT: ]
30093045
// CHECK-NEXT: }

clang/test/AST/ast-dump-traits.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@ void test_unary_expr_or_type_trait() {
4040
// CHECK-NEXT: | | `-EnumDecl {{.*}} <col:3, col:11> col:8{{( imported)?}} referenced E
4141
// CHECK-NEXT: | |-CStyleCastExpr {{.*}} <line:13:3, col:21> 'void' <ToVoid>
4242
// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} <col:10, col:21> 'bool' __is_enum
43+
// CHECK-NEXT: | | `-ElaboratedType {{.*}} 'E' sugar
44+
// CHECK-NEXT: | | `-EnumType {{.*}} 'E'
45+
// CHECK-NEXT: | | `-Enum {{.*}} 'E'
4346
// CHECK-NEXT: | |-CStyleCastExpr {{.*}} <line:15:3, col:30> 'void' <ToVoid>
4447
// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} <col:10, col:30> 'bool' __is_same
48+
// CHECK-NEXT: | | |-BuiltinType {{.*}} 'int'
49+
// CHECK-NEXT: | | `-BuiltinType {{.*}} 'float'
4550
// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:17:3, col:47> 'void' <ToVoid>
4651
// CHECK-NEXT: | `-TypeTraitExpr {{.*}} <col:10, col:47> 'bool' __is_constructible
52+
// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
53+
// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
54+
// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
55+
// CHECK-NEXT: `-BuiltinType {{.*}} 'int'
4756
// CHECK-NEXT: |-FunctionDecl {{.*}} <line:20:1, line:23:1> line:20:6{{( imported)?}} test_array_type_trait 'void ()'
4857
// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:30, line:23:1>
4958
// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:22:3, col:34> 'void' <ToVoid>

clang/test/SemaCXX/cxx23-assume.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -std=c++23 -x c++ %s -verify
22
// RUN: %clang_cc1 -std=c++20 -pedantic -x c++ %s -verify=ext,expected
3+
// RUN: %clang_cc1 -std=c++23 -x c++ %s -verify -fexperimental-new-constant-interpreter
4+
// RUN: %clang_cc1 -std=c++20 -pedantic -x c++ %s -verify=ext,expected -fexperimental-new-constant-interpreter
35

46
struct A{};
57
struct B{ explicit operator bool() { return true; } };

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,15 +2096,10 @@ Symbol *OmpAttributeVisitor::ResolveOmpCommonBlockName(
20962096
if (!name) {
20972097
return nullptr;
20982098
}
2099-
// First check if the Common Block is declared in the current scope
2100-
if (auto *cur{GetContext().scope.FindCommonBlock(name->source)}) {
2101-
name->symbol = cur;
2102-
return cur;
2103-
}
2104-
// Then check parent scope
2105-
if (auto *prev{GetContext().scope.parent().FindCommonBlock(name->source)}) {
2106-
name->symbol = prev;
2107-
return prev;
2099+
if (auto *cb{GetProgramUnitOrBlockConstructContaining(GetContext().scope)
2100+
.FindCommonBlock(name->source)}) {
2101+
name->symbol = cb;
2102+
return cb;
21082103
}
21092104
return nullptr;
21102105
}

flang/test/Semantics/OpenMP/resolve03.f90

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
common /c/ a, b
1010
integer a(3), b
11+
common /tc/ x
12+
integer x
13+
!$omp threadprivate(/tc/)
1114

1215
A = 1
1316
B = 2
@@ -19,4 +22,26 @@
1922
!$omp end parallel
2023
end block
2124
print *, a, b
25+
26+
!$omp parallel
27+
block
28+
!$omp single
29+
x = 18
30+
!ERROR: COMMON block must be declared in the same scoping unit in which the OpenMP directive or clause appears
31+
!$omp end single copyprivate(/tc/)
32+
end block
33+
!$omp end parallel
34+
35+
! Common block names may be used inside nested OpenMP directives.
36+
!$omp parallel
37+
!$omp parallel copyin(/tc/)
38+
x = x + 10
39+
!$omp end parallel
40+
!$omp end parallel
41+
42+
!$omp parallel
43+
!$omp single
44+
x = 18
45+
!$omp end single copyprivate(/tc/)
46+
!$omp end parallel
2247
end

libcxx/test/support/invocable_with_telemetry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class invocable_with_telemetry {
3131
constexpr invocable_with_telemetry(invocable_with_telemetry&& other)
3232
requires std::move_constructible<F>
3333
: f_(std::move(other.f_)),
34-
telemetry_(assert(other.telemetry_ != nullptr), std::exchange(other.telemetry_, nullptr)) {
34+
telemetry_((assert(other.telemetry_ != nullptr), std::exchange(other.telemetry_, nullptr))) {
3535
++telemetry_->moves;
3636
}
3737

0 commit comments

Comments
 (0)