-
Notifications
You must be signed in to change notification settings - Fork 17.1k
[DO NOT MERGE][SSAF][UnsafeBufferUsage] Implement AST visitor that respects the contribution model #188652
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
Closed
Closed
[DO NOT MERGE][SSAF][UnsafeBufferUsage] Implement AST visitor that respects the contribution model #188652
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
cb8c65a
Reapply "[clang][ssaf] Add UnsafeBufferUsage summary extractor for fu…
ziqingluo-90 09fcf76
[ssaf][UnsafeBufferUsage] Add support for extracting unsafe pointers …
ziqingluo-90 613955c
clean up
ziqingluo-90 deef1a0
Address comments
ziqingluo-90 5ffde95
Reapply "[clang][ssaf] Add UnsafeBufferUsage summary extractor for fu…
ziqingluo-90 fe7dd28
[ssaf][UnsafeBufferUsage] Add support for extracting unsafe pointers …
ziqingluo-90 ebd6232
clean up
ziqingluo-90 e26fd17
Address comments
ziqingluo-90 9a21205
[ssaf][UnsafeBufferUsage] Add JSON serialization for UnsafeBufferUsage
ziqingluo-90 1bf9a44
Merge branch 'main' into users/ziqingluo/eng/PR-171735836
ziqingluo-90 8e063bd
fix a conflict merge issue
ziqingluo-90 9a4630d
Fix clang-format issue
ziqingluo-90 5e855a9
Merge branch 'users/ziqingluo/eng/PR-171735836' into users/ziqingluo/…
ziqingluo-90 50ab079
[NFC][SSAF][UnsafeBufferUsage] Separate EntityPointerLevel and Unsafe…
ziqingluo-90 5e83028
[SSAF][UnsafeBufferUsage] Implement AST visitor that respects the con…
ziqingluo-90 620d322
Merge remote-tracking branch 'origin' into users/ziqingluo/eng/PR-171…
ziqingluo-90 e5dbc48
address some comments
ziqingluo-90 2cbbc1a
address comments
ziqingluo-90 8420612
Update clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBuffe…
ziqingluo-90 f8a2e0e
Update clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBuffe…
ziqingluo-90 354f742
Update clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBuffe…
ziqingluo-90 157f3c2
refactor UnsafeBufferUsage serialization API and test for Format inde…
ziqingluo-90 0e7f715
address comments
ziqingluo-90 e4d0b9e
address comments
ziqingluo-90 4d8f738
Merge branch 'main' into users/ziqingluo/eng/PR-171920065
ziqingluo-90 54e480e
address comments
ziqingluo-90 68eddbb
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/U…
ziqingluo-90 70c1962
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/U…
ziqingluo-90 1b980e0
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/U…
ziqingluo-90 b220e30
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/U…
ziqingluo-90 9eebb20
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/U…
ziqingluo-90 74863f2
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/U…
ziqingluo-90 ce07c3c
Update clang/unittests/ScalableStaticAnalysisFramework/Analyses/Unsaf…
ziqingluo-90 d30f0f5
Merge remote-tracking branch 'origin/main' into users/ziqingluo/eng/P…
ziqingluo-90 0a1c297
Merge branch 'main' into users/ziqingluo/eng/PR-171920065
ziqingluo-90 b44a110
[NFC][SSAF][UnsafeBufferUsage] Separate EntityPointerLevel and Unsafe…
ziqingluo-90 f3c29ee
rebase
ziqingluo-90 1cf2c6a
clean up
ziqingluo-90 a71bb3b
Merge remote-tracking branch 'origin/users/ziqingluo/PR-172429193' in…
ziqingluo-90 4c681ab
fix issues after rebase
ziqingluo-90 036f9b1
remove proxy functions for unit-testing UnsafeBufferUsageExtractor
ziqingluo-90 1a7d533
fix clang-format issue
ziqingluo-90 ae57606
fix build issue
ziqingluo-90 8e54890
fix bugs
ziqingluo-90 abc7647
fix typo
ziqingluo-90 63be9b2
fix format
ziqingluo-90 c3a6643
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/E…
ziqingluo-90 4eec9ca
Update clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalyse…
ziqingluo-90 58d8ee8
address comments
ziqingluo-90 a4ccace
[NFC][SSAF] Move EntityPointerLevel to a separate folder
ziqingluo-90 3994ca4
[SSAF][UnsafeBufferUsage] Add APIs to the EntityPointerLevel module f…
ziqingluo-90 11bc5e0
Update clang/lib/ScalableStaticAnalysisFramework/Analyses/EntityPoint…
ziqingluo-90 3b4bddf
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/E…
ziqingluo-90 ab91945
Update clang/include/clang/ScalableStaticAnalysisFramework/Analyses/E…
ziqingluo-90 d44fad7
address comments
ziqingluo-90 0b8f8e7
Merge branch 'main' into users/ziqingluo/PR-172429193-pre-2
ziqingluo-90 39fbbba
fix format
ziqingluo-90 5bfbef7
Update clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalyse…
ziqingluo-90 1f11604
Merge remote-tracking branch 'origin/users/ziqingluo/PR-172429193-pre…
ziqingluo-90 7883cc3
fix issues after merging
ziqingluo-90 2d70920
Merge branch 'users/ziqingluo/PR-172429193-2' of github.com:llvm/llvm…
ziqingluo-90 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
134 changes: 134 additions & 0 deletions
134
clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel.h
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 |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| //===- EntityPointerLevel.h -------------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_ENTITYPOINTERLEVEL_H | ||
| #define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_ENTITYPOINTERLEVEL_H | ||
|
|
||
| #include "clang/AST/Decl.h" | ||
| #include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityId.h" | ||
| #include "clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h" | ||
| #include <set> | ||
|
|
||
| namespace clang::ssaf { | ||
|
|
||
| /// An EntityPointerLevel is associated with a level of the declared | ||
| /// pointer/array type of an entity. In the fully-expanded spelling of the | ||
| /// declared type, a EntityPointerLevel is associated with a '*' (or a '[]`) in | ||
| /// that declaration. | ||
| /// | ||
| /// For example, for 'int *p[10];', there are two EntityPointerLevels. One | ||
| /// is associated with 'int *[10]' of 'p' and the other is associated with 'int | ||
| /// *' of 'p'. | ||
| /// | ||
| /// An EntityPointerLevel can be identified by an EntityId and an unsigned | ||
| /// integer indicating the pointer level: '(EntityId, PointerLevel)'. | ||
| /// An EntityPointerLevel 'P' is valid iff 'P.EntityId' has a pointer type with | ||
| /// at least 'P.PointerLevel' levels (This implies 'P.PointerLevel > 0'). | ||
| /// | ||
| /// For the same example 'int *p[10];', the EntityPointerLevels below are valid: | ||
| /// - '(p, 2)' is associated with the 'int *' part of the declared type of 'p'; | ||
| /// - '(p, 1)' is associated with the 'int *[10]' part of the declared type of | ||
| /// 'p'. | ||
|
ziqingluo-90 marked this conversation as resolved.
|
||
| class EntityPointerLevel { | ||
|
steakhal marked this conversation as resolved.
|
||
| EntityId Entity; | ||
| unsigned PointerLevel; | ||
|
|
||
| friend class EntityPointerLevelTranslator; | ||
| friend llvm::Expected<EntityPointerLevel> | ||
| entityPointerLevelFromJSON(const llvm::json::Value &EPLData, | ||
| JSONFormat::EntityIdFromJSONFn EntityIdFromJSON); | ||
| // For unittests: | ||
| friend EntityPointerLevel buildEntityPointerLevel(EntityId, unsigned); | ||
|
|
||
| // EntityPointerLevel(EntityId Entity, unsigned PointerLevel) | ||
| // : Entity(Entity), PointerLevel(PointerLevel) {} | ||
|
ziqingluo-90 marked this conversation as resolved.
|
||
| EntityPointerLevel(std::pair<EntityId, unsigned> Pair) | ||
| : Entity(Pair.first), PointerLevel(Pair.second) {} | ||
|
|
||
| public: | ||
| EntityId getEntity() const { return Entity; } | ||
| unsigned getPointerLevel() const { return PointerLevel; } | ||
|
|
||
| bool operator==(const EntityPointerLevel &Other) const { | ||
| return std::tie(Entity, PointerLevel) == | ||
| std::tie(Other.Entity, Other.PointerLevel); | ||
| } | ||
|
|
||
| bool operator!=(const EntityPointerLevel &Other) const { | ||
| return !(*this == Other); | ||
| } | ||
|
|
||
| bool operator<(const EntityPointerLevel &Other) const { | ||
| return std::tie(Entity, PointerLevel) < | ||
| std::tie(Other.Entity, Other.PointerLevel); | ||
| } | ||
|
|
||
| /// Compares `EntityPointerLevel`s; additionally, partially compares | ||
| /// `EntityPointerLevel` with `EntityId`. | ||
| struct Comparator { | ||
| using is_transparent = void; | ||
| bool operator()(const EntityPointerLevel &L, | ||
| const EntityPointerLevel &R) const { | ||
| return L < R; | ||
| } | ||
| bool operator()(const EntityId &L, const EntityPointerLevel &R) const { | ||
| return L < R.getEntity(); | ||
| } | ||
| bool operator()(const EntityPointerLevel &L, const EntityId &R) const { | ||
| return L.getEntity() < R; | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| using EntityPointerLevelSet = | ||
| std::set<EntityPointerLevel, EntityPointerLevel::Comparator>; | ||
|
|
||
| /// Translate a pointer/array type expression 'E' to a (set of) | ||
| /// EntityPointerLevel(s) associated with the declared type of the base address | ||
| /// of `E`. If the base address of `E` is not associated with an entity, the | ||
| /// translation result is an empty set. | ||
| /// | ||
| /// \param E the pointer expression to be translated | ||
| /// \param Ctx the AST context of `E` | ||
| /// \param AddEntity the callback provided by the caller to convert EntityNames | ||
| /// to EntityIds. | ||
| llvm::Expected<EntityPointerLevelSet> | ||
| translateEntityPointerLevel(const Expr *E, ASTContext &Ctx, | ||
| std::function<EntityId(EntityName EN)> AddEntity); | ||
|
|
||
| /// Create an EntityPointerLevel (EPL) from a NamedDecl of a pointer/array type. | ||
| /// | ||
| /// \param E the pointer expression to be translated | ||
| /// \param Ctx the AST context of `E` | ||
| /// \param AddEntity the callback provided by the caller to convert EntityNames | ||
| /// to EntityIds. | ||
| /// \param IsFunRet true iff the created EPL is associated with the return type | ||
| /// of a function entity. | ||
| llvm::Expected<EntityPointerLevel> | ||
| createEntityPointerLevel(const NamedDecl *ND, ASTContext &Ctx, | ||
| std::function<EntityId(EntityName EN)> AddEntity, | ||
| bool IsFunRet = false); | ||
|
|
||
| /// Creates a new EntityPointerLevel (EPL) from `E` by incrementing `E`'s | ||
| /// pointer level. | ||
| /// \return the EPL that is associated with the pointee (or array element) type | ||
| /// of `E`'s associated pointer/array tyoe of the same entity. | ||
| EntityPointerLevel incrementPointerLevel(const EntityPointerLevel &E); | ||
|
|
||
| llvm::json::Value | ||
| entityPointerLevelToJSON(const EntityPointerLevel &EPL, | ||
| JSONFormat::EntityIdToJSONFn EntityId2JSON); | ||
|
|
||
| llvm::Expected<EntityPointerLevel> | ||
| entityPointerLevelFromJSON(const llvm::json::Value &EPLData, | ||
| JSONFormat::EntityIdFromJSONFn EntityIdFromJSON); | ||
|
|
||
| /// Proxy function creating EPLs for unit tests: | ||
| EntityPointerLevel buildEntityPointerLevel(EntityId, unsigned); | ||
| } // namespace clang::ssaf | ||
| #endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_ENTITYPOINTERLEVEL_H | ||
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
25 changes: 25 additions & 0 deletions
25
...ng/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevelFormat.h
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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===- EntityPointerLevelFormat.h -------------------------------*- C++-*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_ENTITYPOINTERLEVEL_ENTITYPOINTERLEVELFORMAT_H | ||
| #define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_ENTITYPOINTERLEVEL_ENTITYPOINTERLEVELFORMAT_H | ||
|
|
||
| #include "clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h" | ||
| #include "clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h" | ||
|
|
||
| namespace clang::ssaf { | ||
| llvm::json::Value | ||
| entityPointerLevelToJSON(const EntityPointerLevel &EPL, | ||
| JSONFormat::EntityIdToJSONFn EntityId2JSON); | ||
|
|
||
| Expected<EntityPointerLevel> | ||
| entityPointerLevelFromJSON(const llvm::json::Value &EPLData, | ||
| JSONFormat::EntityIdFromJSONFn EntityIdFromJSON); | ||
| } // namespace clang::ssaf | ||
|
|
||
| #endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_ENTITYPOINTERLEVEL_ENTITYPOINTERLEVELFORMAT_H |
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
35 changes: 0 additions & 35 deletions
35
...g/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.h
This file was deleted.
Oops, something went wrong.
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.
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.