@@ -327,37 +327,52 @@ bool ProgramInfo::link() {
327
327
328
328
// For every global function that is an unresolved external, constrain
329
329
// its parameter types to be wild. Unless it has a bounds-safe annotation.
330
- for (const auto &U : ExternFunctions) {
330
+ for (const auto &U : ExternalFunctionFVCons) {
331
+ std::string FuncName = U.first ;
332
+ FVConstraint *G = U.second ;
331
333
// If we've seen this symbol, but never seen a body for it, constrain
332
334
// everything about it.
333
- std::string FuncName = U.first ;
334
- if (!U.second && !isExternOkay (FuncName)) {
335
- // Some global symbols we don't need to constrain to wild, like
336
- // malloc and free. Check those here and skip if we find them.
337
- FVConstraint *G = getExtFuncDefnConstraint (FuncName);
338
- assert (" Function constraints could not be found!" && G != nullptr );
335
+ // Some global symbols we don't need to constrain to wild, like
336
+ // malloc and free. Check those here and skip if we find them.
337
+ if (!G->hasBody () && !isExternOkay (FuncName)) {
339
338
340
339
// If there was a checked type on a variable in the input program, it
341
340
// should stay that way. Otherwise, we shouldn't be adding a checked type
342
341
// to an extern function.
343
342
std::string Rsn =
344
- " Unchecked pointer in parameter or return of external function " +
345
- FuncName;
343
+ " Unchecked pointer in parameter or return of external function " +
344
+ FuncName;
346
345
if (!G->getReturnVar ()->getIsGeneric ())
347
346
G->getReturnVar ()->constrainToWild (CS, Rsn);
348
347
for (unsigned I = 0 ; I < G->numParams (); I++)
349
348
if (!G->getParamVar (I)->getIsGeneric ())
350
349
G->getParamVar (I)->constrainToWild (CS, Rsn);
351
350
}
352
351
}
352
+ // repeat for static functions
353
+ for (const auto &U :StaticFunctionFVCons) {
354
+ for (const auto &V :U.second ) {
355
+
356
+ std::string FileName = U.first ;
357
+ std::string FuncName = V.first ;
358
+ FVConstraint *G = V.second ;
359
+ if (!G->hasBody () && !isExternOkay (FuncName)) {
360
+
361
+ std::string Rsn =
362
+ " Unchecked pointer in parameter or return of static function " +
363
+ FuncName + " in " + FileName;
364
+ if (!G->getReturnVar ()->getIsGeneric ())
365
+ G->getReturnVar ()->constrainToWild (CS, Rsn);
366
+ for (unsigned I = 0 ; I < G->numParams (); I++)
367
+ if (!G->getParamVar (I)->getIsGeneric ())
368
+ G->getParamVar (I)->constrainToWild (CS, Rsn);
369
+ }
370
+ }
371
+ }
353
372
354
373
return true ;
355
374
}
356
375
357
- bool ProgramInfo::isAnExternFunction (const std::string &FName) {
358
- return !ExternFunctions[FName];
359
- }
360
-
361
376
// Populate Variables, VarDeclToStatement, RVariables, and DepthMap with
362
377
// AST data structures that correspond do the data stored in PDMap and
363
378
// ReversePDMap.
@@ -436,13 +451,6 @@ bool ProgramInfo::insertNewFVConstraint(FunctionDecl *FD, FVConstraint *FVCon,
436
451
// external method.
437
452
ret = insertIntoExternalFunctionMap (ExternalFunctionFVCons,
438
453
FuncName, FVCon);
439
- bool isDef = FVCon->hasBody ();
440
- if (isDef) {
441
- ExternFunctions[FuncName] = true ;
442
- } else {
443
- if (!ExternFunctions[FuncName])
444
- ExternFunctions[FuncName] = false ;
445
- }
446
454
} else {
447
455
// static method
448
456
auto Psl = PersistentSourceLoc::mkPSL (FD, *C);
0 commit comments