Skip to content

Commit abc1f9c

Browse files
Don't allow type arguments to be added to generic function calls in unwritable files. (#591)
Fixes #580.
1 parent 8fab223 commit abc1f9c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang/lib/3C/TypeVariableAnalysis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ bool TypeVarVisitor::VisitCallExpr(CallExpr *CE) {
9797
FDef = FD;
9898
if (auto *FVCon = Info.getFuncConstraint(FDef, Context)) {
9999
// if we need to rewrite it but can't (macro, etc), it isn't safe
100-
bool ForcedInconsistent = !typeArgsProvided(CE)
101-
&& !Rewriter::isRewritable(CE->getExprLoc());
100+
bool ForcedInconsistent =
101+
!typeArgsProvided(CE) &&
102+
(!Rewriter::isRewritable(CE->getExprLoc()) ||
103+
!canWrite(PersistentSourceLoc::mkPSL(CE, *Context).getFileName()));
102104
// Visit each function argument, and if it use a type variable, insert it
103105
// into the type variable binding map.
104106
unsigned int I = 0;

clang/test/3C/canwrite_constraints.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ void unwritable_func_with_itype(int *p : itype(_Array_ptr<int>)) {}
5959
void unwritable_func_with_itype_and_bounds(int *p
6060
: itype(_Array_ptr<int>) count(12)) {
6161
}
62+
63+
// Test for https://github.com/correctcomputation/checkedc-clang/issues/580
64+
_Itype_for_any(T) void my_generic_function(void *p : itype(_Ptr<T>));
65+
66+
void unwritable_type_argument() {
67+
int i;
68+
my_generic_function(&i);
69+
}

0 commit comments

Comments
 (0)