-
Notifications
You must be signed in to change notification settings - Fork 5
Bugfix#349 #361
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
Bugfix#349 #361
Changes from 4 commits
bea4d41
80a5555
5d4f53c
c35b1cf
996a837
bcfb668
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// RUN: 3c -addcr -alltypes %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s | ||
// RUN: 3c -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s | ||
// RUN: 3c -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - | ||
// RUN: 3c -addcr -alltypes %s | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s | ||
// RUN: 3c -addcr %s | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s | ||
// RUN: 3c -addcr %s | %clang -c -fcheckedc-extension -x c -o %t1.unused - | ||
|
||
// General demonstration | ||
_Itype_for_any(T) void *test_single(void *a : itype(_Ptr<T>), void *b : itype(_Ptr<T>)) : itype(_Ptr<T>); | ||
|
@@ -157,3 +157,17 @@ void *example1(void * ptr, unsigned int size) { | |
// CHECK: ret = realloc<void>(ptr, size); | ||
return ret; | ||
} | ||
|
||
// Issue #349. Check that the parameter doesn't inherit the double pointer argument within do_doubleptr | ||
_Itype_for_any(T) | ||
void incoming_doubleptr(void* ptr : itype(_Array_ptr<T>)) { | ||
// CHECK_ALL: void incoming_doubleptr(_Array_ptr<T> ptr : itype(_Array_ptr<T>)) { | ||
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. Again, this seems very weird to me. I'm not sure why the 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. I does seem odd that this ends up with both I think the fix this PR makes means that the type of 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. Yes, before the fix it was being rewritten with two pointer levels. But it is safe, so shouldn't it be rewritten with the new type and no Itype? Or is that just how it will be done with the liberal itypes enhancement? 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. Two things: (1) It doesn't make sense to have a checked pointer to the left of the colon, on an itype. Having 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. Perhaps I misunderstood the bug. In regards to (2), this bugfix does not add the rewriting, it only makes it correct. It was being rewritten in the test originally, but there was no 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. I see. It shouldn't have been getting rewritten, I don't believe. So maybe that's a bug in addition? Are these bugs something one can tease apart? 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. If you'll accept separate bugfixes for the two issues mentioned above, than this one as-is fixes the correctness issue, and is ready to merge pending any conflicts with code merged in the mean time. I'll make a new issue for the duplicated type, which is inconvenient but compiles correctly. 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. OK. Just to get it on the record: By "duplicated type" you mean that |
||
return; | ||
} | ||
|
||
void do_doubleptr(int count) { | ||
int **arr = malloc(sizeof(int*) * count); | ||
// CHECK_ALL: _Array_ptr<_Ptr<int>> arr : count(count) = malloc<_Ptr<int>>(sizeof(int*) * count); | ||
incoming_doubleptr(arr); | ||
// CHECK_ALL: incoming_doubleptr<_Ptr<int>>(arr); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: 3c -addcr -alltypes %s | FileCheck -match-full-lines %s | ||
|
||
// XFAIL: * | ||
|
||
// This fails because the type variable is used to constrain both calls to `incoming_doubleptr`. | ||
// To be correct, the usage of a type variable should be independent at each call site. | ||
|
||
// adapted from type_params.c | ||
#include <stddef.h> | ||
_Itype_for_any(T) void *malloc(size_t size) : itype(_Array_ptr<T>) byte_count(size); | ||
|
||
_Itype_for_any(T) | ||
void incoming_doubleptr(_Array_ptr<T> ptr : itype(_Array_ptr<T>)) { | ||
return; | ||
} | ||
|
||
void do_doubleptr(int count) { | ||
int **arr = malloc(sizeof(int*) * count); | ||
// CHECK: _Array_ptr<_Ptr<int>> arr : count(count) = malloc<_Ptr<int>>(sizeof(int*) * count); | ||
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. Just to be clear: This is the rewriting that should happen, but does not? What happens instead? 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. It is rewritten as |
||
incoming_doubleptr(arr); | ||
} | ||
|
||
// adding this function changes the infered type of the previous one unnecessarily | ||
void interfere_doubleptr(void) | ||
{ | ||
float fl _Checked[5][5] = {}; | ||
incoming_doubleptr(fl); | ||
} |
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.
Was this test not passing at all, before? I see you have not changed the expectation of what
-alltypes
will produce, in terms of changing the source file. So I'm confused how you are testing the change that you made toConstraintVariables.cpp
.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.
This was one of the tests that I previously identified for not running clang on the output of 3c. It turns out, that would cause an error, explained in more detail with simplified example in issue #349. This change was verified by the addition of the compilation line, and the lack of effect on the suite of regression tests. I was hesitant to change the test in other ways, since I didn't write it or analyze why it exists. But I can add a "CHECKALL" line at the location that allowed it to compile.