-
Notifications
You must be signed in to change notification settings - Fork 79
Clang issue445 #506
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
Clang issue445 #506
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
664ca50
Checkpoint intermediate work.
86340b4
changes after David's initial code review
5b19beb
use the original format for DiagnosticSemaKinds.td, Type.cpp and Sema…
8e5aaaf
change format for comments; array bug fixed
6de6465
fix array type cast bug
fffc2cb
fix bug caused by illegal struct/union types
e6732cc
remove unnecessary handling for function types
5780048
handle _Ptr/_Array_ptr/_Nt_array_ptr types separately
bf4b90a
remove unnecessary else stmt
61019e0
additional checking for (1) int with a bounds expr (2) unchecked poin…
a3a32db
for unchecked pointers with bounds expr in checked scope case, handle…
9c48467
remove comma
14c6107
polish diag def err
5d844dc
minor format change; consider int with bounds as an indepedent err
c66573f
polish comments
67e73a6
int->integer; remove white spaces
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4109,6 +4109,60 @@ bool Type::isOrContainsUncheckedType() const { | |
| } | ||
| } | ||
|
|
||
| // containsCheckedValue - check whether a field type is a checked type or is a | ||
|
Member
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. This comment needs to be updated. |
||
| // constructed type (array, pointer, function) that uses a checked type. | ||
| bool Type::containsCheckedValue() const { | ||
| const Type *current = CanonicalType.getTypePtr(); | ||
| switch (current->getTypeClass()) { | ||
| case Type::Pointer: { | ||
| const PointerType *ptr = cast<PointerType>(current); | ||
| return ptr->isCheckedPointerType(); | ||
| } | ||
| case Type::ConstantArray: | ||
| case Type::DependentSizedArray: | ||
| case Type::IncompleteArray: | ||
| case Type::VariableArray: { | ||
| return current->getPointeeOrArrayElementType()->containsCheckedValue(); | ||
| } | ||
|
|
||
| //Use RecordType to process Struct/Union | ||
| case Type::Record: { | ||
| const RecordType *RT = cast<RecordType>(current); | ||
| // if this is an illegal type, we don't proceed (e.g. struct S{ S s; int a;...}) | ||
| if (RT->getDecl()->isInvalidDecl()) | ||
| return false; | ||
|
|
||
| // if this is a struct/union type, iterate all its members | ||
|
Member
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. Wording suggestion: iterate all -> iterate over all |
||
| bool hasCheckedField = false; | ||
| for (FieldDecl *FD : RT->getDecl()->fields()) { | ||
| if (FD->getType()->isRecordType()) { | ||
| hasCheckedField = FD->getType()->containsCheckedValue(); | ||
| } | ||
| // if this field is not a RecordType variable but contains a checked pointer, | ||
| // its type must be (1) _Ptr (2) _Array_ptr or (3) _Nt_array_ptr | ||
| else if (FD->getType()->containsCheckedValue()) { | ||
| // Case 1: _Ptr always needs to be initialized | ||
| if (FD->getType()->isCheckedPointerPtrType()) | ||
| hasCheckedField = true; | ||
| // Case 2: _Array_ptr needs to be initialized if it has bounds and the bounds are NOT unknown; | ||
| // Case 3: _Nt_array_ptr needs to be initialized if (1) it has no bounds specified | ||
| // or (2) it has bounds but the bounds are unknown; | ||
| // since for _Nt_array_ptr we always attach default bounds of count(0) to a decl, | ||
| // if no bounds are specified (done in ActOnBoundsDecl and before this checking), | ||
| // we can simplified the checking by combining case 2 and 3 | ||
| else if (FD->getType()->isCheckedPointerArrayType() && FD->hasBoundsExpr()) { | ||
| if (!FD->getBoundsExpr()->isUnknown()) | ||
| hasCheckedField = true; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| return hasCheckedField; | ||
| } | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
| // hasVariadicType - check whether a type has variable arguments | ||
| // or is a constructed type(array, pointer, function) having variable arguments. | ||
| bool Type::hasVariadicType() const { | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the name integer in place of int in the error messages.