Skip to content

Commit c723475

Browse files
committed
remove ExternalFunctions; make bodyless static wild
1 parent 38b371a commit c723475

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

clang/include/clang/3C/ProgramInfo.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ class ProgramInfo : public ProgramVariableAdder {
8383
std::string FileName) const;
8484

8585

86-
// Check if the given function is an extern function.
87-
bool isAnExternFunction(const std::string &FName);
88-
8986
// Called when we are done adding constraints and visiting ASTs.
9087
// Links information about global symbols together and adds
9188
// constraints where appropriate.
@@ -132,10 +129,9 @@ class ProgramInfo : public ProgramVariableAdder {
132129
// Is the ProgramInfo persisted? Only tested in asserts. Starts at true.
133130
bool persisted;
134131

135-
// Map of global decls for which we don't have a body, the keys are
136-
// names of external functions/vars, the value is whether the body/def
132+
// Map of global decls for which we don't have a definition, the keys are
133+
// names of external vars, the value is whether the def
137134
// has been seen before.
138-
std::map<std::string, bool> ExternFunctions;
139135
std::map<std::string, bool> ExternGVars;
140136

141137
// Maps for global/static functions, global variables

clang/lib/3C/ProgramInfo.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -327,37 +327,52 @@ bool ProgramInfo::link() {
327327

328328
// For every global function that is an unresolved external, constrain
329329
// 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;
331333
// If we've seen this symbol, but never seen a body for it, constrain
332334
// 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)) {
339338

340339
// If there was a checked type on a variable in the input program, it
341340
// should stay that way. Otherwise, we shouldn't be adding a checked type
342341
// to an extern function.
343342
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;
346345
if (!G->getReturnVar()->getIsGeneric())
347346
G->getReturnVar()->constrainToWild(CS, Rsn);
348347
for (unsigned I = 0; I < G->numParams(); I++)
349348
if (!G->getParamVar(I)->getIsGeneric())
350349
G->getParamVar(I)->constrainToWild(CS, Rsn);
351350
}
352351
}
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+
}
353372

354373
return true;
355374
}
356375

357-
bool ProgramInfo::isAnExternFunction(const std::string &FName) {
358-
return !ExternFunctions[FName];
359-
}
360-
361376
// Populate Variables, VarDeclToStatement, RVariables, and DepthMap with
362377
// AST data structures that correspond do the data stored in PDMap and
363378
// ReversePDMap.
@@ -436,13 +451,6 @@ bool ProgramInfo::insertNewFVConstraint(FunctionDecl *FD, FVConstraint *FVCon,
436451
// external method.
437452
ret = insertIntoExternalFunctionMap(ExternalFunctionFVCons,
438453
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-
}
446454
} else {
447455
// static method
448456
auto Psl = PersistentSourceLoc::mkPSL(FD, *C);

0 commit comments

Comments
 (0)