You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following code (which was based on a test I was writing for #651):
typedefint*T;
voidbar(Tx, Ty) {
x=1; // warning: incompatible integer to pointer conversion assigning to 'T' (aka 'int *') from 'int'y= (T)1;
}
Before #690, 3C makes no changes to this code. After #690, 3C converts the code to:
typedef_Ptr<int>T;
voidbar(int*x : itype(T), int*y : itype(T)) {
x=1; // warning: incompatible integer to pointer conversion assigning to 'T' (aka 'int *') from 'int'y= (T)1; // error: expression has unknown bounds, cast to ptr<T> expects source to have bounds
}
which has a compile error. checkedc#1169 does not fix the problem; apparently it is with the C-style cast from int to T (i.e., _Ptr<int>), which is never a valid cast, not the assignment to y. I guess when 3C sees the unsafe cast from int to T, it needs to either constrain T to wild or expand T to int *, a bit like it does in the function parameters.
The text was updated successfully, but these errors were encountered:
It looks like the fundamental issue here is that the constraint variable allocated for a CastExpression doesn't record typedef information. This gives a better conversion for your example, but I haven't looked into it deeper.
diff --git a/clang/lib/3C/ConstraintResolver.cpp b/clang/lib/3C/ConstraintResolver.cpp
index 0964e27e6938..9477cc45defc 100644
--- a/clang/lib/3C/ConstraintResolver.cpp+++ b/clang/lib/3C/ConstraintResolver.cpp@@ -810,6 +810,7 @@ bool ConstraintResolver::isCastofGeneric(CastExpr *C) {
// if the expression is inside a macro.
PVConstraint *ConstraintResolver::getRewritablePVConstraint(Expr *E) {
PVConstraint *P = new PVConstraint(E, Info, *Context);
+ Info.unifyIfTypedef(E->getType(), *Context, P);
auto PSL = PersistentSourceLoc::mkPSL(E, *Context);
Info.constrainWildIfMacro(P, E->getExprLoc(), &PSL);
return P;
The new conversion is
typedefint*T;
voidbar(Tx : itype(_Ptr<int>), Ty : itype(_Ptr<int>)) {
x=1; // warning: incompatible integer to pointer conversion assigning to 'T' (aka 'int *') from 'int'y= (T)1;
}
It would be nice if a proper fix to this issue could modify the ConstraintVariable constructor so that unifyIfTypedef doesn't need to be called whenever one is constructed. Although, I'm entirelynot entirely confident that every variable whose type is a TypedefType should be constrained as a typedef by 3C. For instance, if a variable has a typedef type, but that type is never written anywhere in the source code, then it doesn't need to constrained as a typedef. This might come up for internal constraint variables generated for implicit casts.
For instance, if a variable has a typedef type, but that type is never written anywhere in the source code, then it doesn't need to constrained as a typedef. This might come up for internal constraint variables generated for implicit casts.
That sounds like an issue similar to #618. Maybe we can implement one test for whether the type is written in the source code and use it for both purposes.
Uh oh!
There was an error while loading. Please reload this page.
Consider the following code (which was based on a test I was writing for #651):
Before #690, 3C makes no changes to this code. After #690, 3C converts the code to:
which has a compile error. checkedc#1169 does not fix the problem; apparently it is with the C-style cast from
int
toT
(i.e.,_Ptr<int>
), which is never a valid cast, not the assignment toy
. I guess when 3C sees the unsafe cast fromint
toT
, it needs to either constrainT
to wild or expandT
toint *
, a bit like it does in the function parameters.The text was updated successfully, but these errors were encountered: