forked from checkedc/checkedc-clang
-
Notifications
You must be signed in to change notification settings - Fork 5
Context sensitive array bounds for all function calls #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| #include <stdint.h> | ||
| #include <string> | ||
| #include "clang/AST/ASTContext.h" | ||
| #include "clang/CConv/PersistentSourceLoc.h" | ||
|
|
||
| typedef uint32_t BoundsKey; | ||
|
|
||
|
|
@@ -28,17 +29,18 @@ class ProgramVarScope { | |
| FunctionScopeKind, | ||
| // Function parameter scope. | ||
| FunctionParamScopeKind, | ||
| // Context sensitive argument scope. | ||
| CtxFunctionArgScopeKind, | ||
| // Struct scope. | ||
| StructScopeKind, | ||
| // Global scope. | ||
| GlobalScopeKind, | ||
| }; | ||
| ScopeKind getKind() const { return Kind; } | ||
|
|
||
| private: | ||
| ScopeKind Kind; | ||
| protected: | ||
| ProgramVarScope(ScopeKind K): Kind(K) { } | ||
| ScopeKind Kind; | ||
| public: | ||
| virtual ~ProgramVarScope() { } | ||
|
|
||
|
|
@@ -116,7 +118,7 @@ class StructScope : public ProgramVarScope { | |
|
|
||
| private: | ||
| std::string StName; | ||
| static std::map<std::string, StructScope*> StScopeMap; | ||
| static std::map<std::string, StructScope *> StScopeMap; | ||
| }; | ||
|
|
||
| class FunctionScope; | ||
|
|
@@ -135,7 +137,8 @@ class FunctionParamScope : public ProgramVarScope { | |
| } | ||
|
|
||
| bool operator==(const ProgramVarScope &O) const { | ||
| if (const FunctionParamScope *FPS = clang::dyn_cast<FunctionParamScope>(&O)) { | ||
| if (const FunctionParamScope *FPS = | ||
| clang::dyn_cast<FunctionParamScope>(&O)) { | ||
| return (FPS->FName == FName && FPS->IsStatic == IsStatic); | ||
| } | ||
| return false; | ||
|
|
@@ -153,15 +156,73 @@ class FunctionParamScope : public ProgramVarScope { | |
| return "FuncParm_" + FName; | ||
| } | ||
|
|
||
| static FunctionParamScope *getFunctionParamScope(std::string FnName, | ||
| bool IsSt); | ||
| std::string getFName() const { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this instead return a
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. Done. |
||
| return FName; | ||
| } | ||
|
|
||
| private: | ||
| bool getIsStatic() const { | ||
| return IsStatic; | ||
| } | ||
|
|
||
| static FunctionParamScope * | ||
| getFunctionParamScope(std::string FnName, bool IsSt); | ||
|
|
||
| protected: | ||
| std::string FName; | ||
| bool IsStatic; | ||
|
|
||
| private: | ||
| static std::map<std::pair<std::string, bool>, | ||
| FunctionParamScope*> FnParmScopeMap; | ||
| FunctionParamScope *> FnParmScopeMap; | ||
| }; | ||
|
|
||
| // Context-sensitive arguments scope. | ||
| class CtxFunctionArgScope : public FunctionParamScope { | ||
| public: | ||
| friend class FunctionScope; | ||
| CtxFunctionArgScope(std::string FN, bool IsSt, | ||
| const PersistentSourceLoc &CtxPSL) : | ||
| FunctionParamScope(FN, IsSt) { | ||
| PSL = CtxPSL; | ||
| this->Kind = CtxFunctionArgScopeKind; | ||
| } | ||
|
|
||
| virtual ~CtxFunctionArgScope() { } | ||
|
|
||
| static bool classof(const ProgramVarScope *S) { | ||
| return S->getKind() == CtxFunctionArgScopeKind; | ||
| } | ||
|
|
||
| bool operator==(const ProgramVarScope &O) const { | ||
| if (const CtxFunctionArgScope *FPS = | ||
| clang::dyn_cast<CtxFunctionArgScope>(&O)) { | ||
| return (FPS->FName == FName && | ||
| FPS->IsStatic == IsStatic && | ||
| !(FPS->PSL < PSL || PSL < FPS->PSL)); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| bool operator!=(const ProgramVarScope &O) const { | ||
| return !(*this == O); | ||
| } | ||
|
|
||
| bool operator<(const ProgramVarScope &O) const { | ||
| return clang::isa<GlobalScope>(&O); | ||
| } | ||
|
|
||
| std::string getStr() const { | ||
| return "CtxFuncArg_" + FName; | ||
| } | ||
|
|
||
| static CtxFunctionArgScope * | ||
| getCtxFunctionParamScope(FunctionParamScope *FPS, | ||
| const PersistentSourceLoc &PSL); | ||
|
|
||
| private: | ||
| PersistentSourceLoc PSL; | ||
|
|
||
| static std::map<std::tuple<std::string, bool, PersistentSourceLoc>, | ||
| CtxFunctionArgScope *> CtxFnArgScopeMap; | ||
| }; | ||
|
|
||
| class FunctionScope : public ProgramVarScope { | ||
|
|
@@ -177,10 +238,12 @@ class FunctionScope : public ProgramVarScope { | |
| } | ||
|
|
||
| bool operator==(const ProgramVarScope &O) const { | ||
| if (const FunctionScope *FS = clang::dyn_cast<FunctionScope>(&O)) { | ||
| if (const FunctionScope *FS = | ||
| clang::dyn_cast<FunctionScope>(&O)) { | ||
| return (FS->FName == FName && FS->IsStatic == IsStatic); | ||
| } | ||
| if (const FunctionParamScope *FPS = clang::dyn_cast<FunctionParamScope>(&O)) { | ||
| if (const FunctionParamScope *FPS = | ||
| clang::dyn_cast<FunctionParamScope>(&O)) { | ||
| return (FPS->FName == FName && FPS->IsStatic == IsStatic); | ||
| } | ||
| return false; | ||
|
|
@@ -198,25 +261,29 @@ class FunctionScope : public ProgramVarScope { | |
| return "InFunc_" + FName; | ||
| } | ||
|
|
||
| static FunctionScope *getFunctionScope(std::string FnName, bool IsSt); | ||
| static FunctionScope *getFunctionScope(std::string FnName, | ||
| bool IsSt); | ||
|
|
||
| private: | ||
| std::string FName; | ||
| bool IsStatic; | ||
|
|
||
| static std::map<std::pair<std::string, bool>, FunctionScope*> FnScopeMap; | ||
| static std::map<std::pair<std::string, bool>, FunctionScope *> | ||
| FnScopeMap; | ||
| }; | ||
|
|
||
| // Class that represents a program variable along with its scope. | ||
| class ProgramVar { | ||
| public: | ||
| ProgramVar(BoundsKey VK, std::string VName, ProgramVarScope *PVS, bool IsCons) : | ||
| ProgramVar(BoundsKey VK, std::string VName, ProgramVarScope *PVS, | ||
| bool IsCons) : | ||
| K(VK), VarName(VName), VScope(PVS), IsConstant(IsCons) { } | ||
|
|
||
| ProgramVar(BoundsKey VK, std::string VName, ProgramVarScope *PVS) : | ||
| ProgramVar(VK, VName, PVS, false) { } | ||
|
|
||
| ProgramVarScope *getScope() { return VScope; } | ||
| void setScope(ProgramVarScope *PVS) { this->VScope = PVS; } | ||
| BoundsKey getKey() { return K; } | ||
| bool IsNumConstant() { return IsConstant; } | ||
| std::string mkString(bool GetKey = false); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.