@@ -834,10 +834,31 @@ PointerVariableConstraint::mkString(Constraints &CS,
834
834
if (!ForItype && InferredGenericIndex == -1 && isVoidPtr ())
835
835
K = Atom::A_Wild;
836
836
837
+ // In a case like `_Ptr<T> g[1]`, we need to push the ` g` onto EndStrs
838
+ // before we can push the `>` and start drilling into T.
839
+ //
840
+ // Exception: In a case like `int *g[1]`, we don't want an extra space after
841
+ // the `*` but we don't yet know whether we have a `*`, so we skip emitting
842
+ // the name. We have to also skip the addArrayAnnotations because it would
843
+ // cause the array annotations to be emitted before the name.
844
+ //
845
+ // Exception to the exception: In a case like `void (*fs[2])()`, we still
846
+ // want to avoid emitting the name (which would add an extra space after the
847
+ // `*`), but we _do_ need to call addArrayAnnotations so the array
848
+ // annotations end up with the variable name rather than after the function
849
+ // parameter list. The function pointer code knows to emit the name before
850
+ // EndStrs.
851
+ //
852
+ // This passes the current regression tests but feels very ad-hoc.
853
+ // REVIEW: Help me redesign this code!
837
854
if (PrevArr && ArrSizes.at (TypeIdx).first != O_SizedArray && !EmittedName) {
838
- EmittedName = true ;
839
- addArrayAnnotations (ConstArrs, EndStrs);
840
- EndStrs.push_front (" " + UseName);
855
+ if (K != Atom::A_Wild || FV != nullptr ) {
856
+ addArrayAnnotations (ConstArrs, EndStrs);
857
+ }
858
+ if (K != Atom::A_Wild) {
859
+ EmittedName = true ;
860
+ EndStrs.push_front (" " + UseName);
861
+ }
841
862
}
842
863
PrevArr = ArrSizes.at (TypeIdx).first == O_SizedArray;
843
864
@@ -927,6 +948,8 @@ PointerVariableConstraint::mkString(Constraints &CS,
927
948
// the the stack array type.
928
949
if (PrevArr && !EmittedName && AllArrays) {
929
950
EmittedName = true ;
951
+ // Note: If the whole type is an array, we can't have a "*", so we don't
952
+ // need to worry about an extra space.
930
953
EndStrs.push_front (" " + UseName);
931
954
}
932
955
@@ -965,8 +988,14 @@ PointerVariableConstraint::mkString(Constraints &CS,
965
988
}
966
989
967
990
// No space after itype.
968
- if (!EmittedName && !UseName.empty ())
969
- Ss << " " << UseName;
991
+ if (!EmittedName && !UseName.empty ()) {
992
+ // REVIEW: Is there a better way? This might actually be less of a
993
+ // maintenance problem than trying to have all code paths correctly set an
994
+ // explicit flag for whether to add a space.
995
+ if (!StringRef (Ss.str ()).endswith (" *" ))
996
+ Ss << " " ;
997
+ Ss << UseName;
998
+ }
970
999
971
1000
// Final array dropping.
972
1001
if (!ConstArrs.empty ()) {
0 commit comments