Skip to content

Commit 6d3c495

Browse files
Bonus fix: Avoid an extra space after a return type ending in *.
I'm including this because the code fix was similar to a fix that was originally in the multi-decl overhaul before the same fix was needed in #702 and I was aware of the issue from item 4 of #703.
1 parent d4923e2 commit 6d3c495

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

clang/lib/3C/ConstraintVariables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ PointerVariableConstraint::mkString(Constraints &CS,
10011001
Ss << Str;
10021002
}
10031003

1004-
if (IsReturn && !ForItype)
1004+
if (IsReturn && !ForItype && !StringRef(Ss.str()).endswith("*"))
10051005
Ss << " ";
10061006

10071007
return Ss.str();

clang/test/3C/itype_typedef.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void test2(td2 a) {
3434
typedef int *td3;
3535
td3 test3() {
3636
//CHECK: typedef _Ptr<int> td3;
37-
//CHECK: int * test3(void) : itype(td3) {
37+
//CHECK: int *test3(void) : itype(td3) {
3838
return (int*) 1;
3939
}
4040

clang/test/3C/itypes_for_extern.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ int *baz(int *a, int len, int *b) {
3030
return a;
3131
}
3232

33+
// REVIEW: The problem described in the following comment has been fixed roughly
34+
// in the "first way": the canonical form of the type from mkString no longer
35+
// has the space, so the test will pass as long as the original code didn't have
36+
// the space either. If we still want to pursue the second fix, do we want to
37+
// note that somehow, e.g., by filing an issue?
3338
// FIXME: The space between after the first star is needed for the idempotence
3439
// test to pass. If there isn't a space there, 3c will add one when
3540
// re-run on its original output. This should be fixed ideally in two
3641
// ways. First, the space shouldn't be added when not present in the
3742
// original source, and second, the second conversion should not rewrite
3843
// the declaration.
39-
void buz(int * (*f)(int *, int *)) {}
40-
//CHECK: void buz(int * ((*f)(int *, int *)) : itype(_Ptr<_Ptr<int> (_Ptr<int>, _Ptr<int>)>)) _Checked {}
44+
void buz(int *(*f)(int *, int *)) {}
45+
//CHECK: void buz(int *((*f)(int *, int *)) : itype(_Ptr<_Ptr<int> (_Ptr<int>, _Ptr<int>)>)) _Checked {}
4146

4247
typedef int * int_star;
4348
void typedef_test(int_star p) {}

0 commit comments

Comments
 (0)