Prevent static variables declarations from using free type variables#718
Prevent static variables declarations from using free type variables#718
Conversation
…ype variables referenced in a type
…ic type declarations
…hen checking the declaration type
| def warn_vector_long_decl_spec_combination : Warning< | ||
| "Use of 'long' with '__vector' is deprecated">, InGroup<Deprecated>; | ||
|
|
||
| def err_static_decl_uses_free_type_variable : Error< |
There was a problem hiding this comment.
I think the error messages needs to be changed to be more understandable by C programmers. Most of them won't know what a free type variable. How about something like the following? "static variable cannot have a type variable bound by an enclosing scope"
There was a problem hiding this comment.
I think you need to include the type and indicate in the message that the problem is with type. Something akin to:
"type for static variable '%0' cannot use a type variable '%1' that is bound by an enclosing scope"
or
"static variable '%0' has a type '%1' that uses a type variable bound by an enclosing scope'
clang/lib/Sema/CheckedCSubst.cpp
Outdated
|
|
||
| /// Returns the list of free typedef declarations referenced in the given type. | ||
| /// Typedef declarations enable more readable diagnostics than type variable types. | ||
| std::vector<const TypedefNameDecl *> findTypedefDecls(QualType Tpe) { |
There was a problem hiding this comment.
Instead of Type, I'd suggest Ty as the variable name.
dtarditi
left a comment
There was a problem hiding this comment.
I think the error message needs to indicate that the problem is with the use of type variable in the type of the variable.
| def warn_vector_long_decl_spec_combination : Warning< | ||
| "Use of 'long' with '__vector' is deprecated">, InGroup<Deprecated>; | ||
|
|
||
| def err_static_decl_uses_free_type_variable : Error< |
There was a problem hiding this comment.
I think you need to include the type and indicate in the message that the problem is with type. Something akin to:
"type for static variable '%0' cannot use a type variable '%1' that is bound by an enclosing scope"
or
"static variable '%0' has a type '%1' that uses a type variable bound by an enclosing scope'
… location rather than the static variable location
This pull requests extends array bounds inference to support inferring lower
bounds for array pointers and inserting using Checked C range bounds.
For example:
char simple_lower_bound(int *a, int l) {
int *b = a;
while (b - a < l && *b != 42)
b++;
return b - a < l;
}
3C can now infer bounds for b even though a standard count bound would be
invalidated by the increment b++.
char simple_lower_bound(_Array_ptr<int> a : count(l), int l) {
_Array_ptr<int> b : bounds(a, a + l) = a;
while (b - a < l && *b != 42)
b++;
return b - a < l;
}
The inference is also able to automatically fatten pointers by generating lower
bounds where none exists in the source code.
Co-authored-by: Matt McCutchen (Correct Computation) <matt@correctcomputation.com>
(See #684)
Emit an error for each usage of a free type variable in the declaration of a static variable. The following:
will emit the following:
These errors are emitted at the location of the static variable. For example:

Future work: disallow free type variables in assignments to static variables (see #717)
Testing: