Skip to content

Commit c9bbce1

Browse files
committed
[PP-EXT] Support usage of spec_index_cmp in conditions
1 parent 6dfc782 commit c9bbce1

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,15 +935,22 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
935935
}
936936
else if (IsSpecIdxCmp) {
937937
auto tfi = Context.CreateTypeSourceInfo(Context.VoidPtrTy);
938-
ParmVarDecl* PVDecl = ParmVarDecl::Create(Context,
938+
ParmVarDecl* PVDecl1 = ParmVarDecl::Create(Context,
939939
Context.getTranslationUnitDecl(),
940940
NameLoc, NameLoc, nullptr,
941941
Context.VoidPtrTy,
942942
tfi,
943943
clang::StorageClass::SC_None,
944944
nullptr);
945-
Params.push_back(PVDecl);
946-
Params.push_back(PVDecl);
945+
ParmVarDecl* PVDecl2 = ParmVarDecl::Create(Context,
946+
Context.getTranslationUnitDecl(),
947+
NameLoc, NameLoc, nullptr,
948+
Context.VoidPtrTy,
949+
tfi,
950+
clang::StorageClass::SC_None,
951+
nullptr);
952+
Params.push_back(PVDecl1);
953+
Params.push_back(PVDecl2);
947954
}
948955
else if (IsGetSpecPtr) {
949956
auto tfi = Context.CreateTypeSourceInfo(Context.IntTy);

clang/lib/Sema/SemaExpr.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,15 +2594,22 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
25942594
}
25952595
else if (IsSpecIdxCmp) {
25962596
auto tfi = Context.CreateTypeSourceInfo(Context.VoidPtrTy);
2597-
ParmVarDecl* PVDecl = ParmVarDecl::Create(Context,
2597+
ParmVarDecl* PVDecl1 = ParmVarDecl::Create(Context,
25982598
Context.getTranslationUnitDecl(),
25992599
NameLoc, NameLoc, nullptr,
26002600
Context.VoidPtrTy,
26012601
tfi,
26022602
clang::StorageClass::SC_None,
26032603
nullptr);
2604-
Params.push_back(PVDecl);
2605-
Params.push_back(PVDecl);
2604+
ParmVarDecl* PVDecl2 = ParmVarDecl::Create(Context,
2605+
Context.getTranslationUnitDecl(),
2606+
NameLoc, NameLoc, nullptr,
2607+
Context.VoidPtrTy,
2608+
tfi,
2609+
clang::StorageClass::SC_None,
2610+
nullptr);
2611+
Params.push_back(PVDecl1);
2612+
Params.push_back(PVDecl2);
26062613
}
26072614
NewD->setParams(Params);
26082615
// TODO: Remove it

clang/test/CodeGen/Figure.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ int main() {
262262
// CHECK-RT-NEXT: Circ+Rect cmp: -1
263263
int res_cmp4 = spec_index_cmp(&fc, &fr);
264264
printf("Circ+Rect cmp: %d\n", res_cmp4);
265+
266+
// CHECK-RT-NEXT: Rect+Circ cmp: -1
267+
res_cmp4 = spec_index_cmp(&fr, &fc);
268+
printf("Rect+Circ cmp: %d\n", res_cmp4);
269+
270+
// CHECK-RT-NEXT: Checked usage spec_index_cmp in condition
271+
if (spec_index_cmp(&fc, &fc) >= 0) {
272+
printf("Checked usage spec_index_cmp in condition\n");
273+
}
265274
}
266275

267276
// This code just checking comilation

0 commit comments

Comments
 (0)