-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Forbid casting of struct types #1873
Conversation
6f14aeb
to
11d9380
Compare
tests/semantic_analyser.cpp
Outdated
{ | ||
// Casting struct by value is forbidden | ||
test("struct type { int field; }" | ||
"kprobe:f { $s = (struct type)cpu; $u = (uint32)$s; }", |
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 seems to test the wrong thing
stdin:1:59-74: ERROR: Cannot convert unsigned int64 to struct
struct type { int field; } struct b { int a }; k:f { $s = (struct type )cpu; }
~~~~~~~~~~~~~~~
src/ast/semantic_analyser.cpp
Outdated
if (cast.expr->type.IsRecordTy()) | ||
{ | ||
LOG(ERROR, cast.loc, err_) | ||
<< "Cannot cast struct type \"" << cast.expr->type << "\""; |
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.
would be nice to include the target type as well, but that means shuffling a bit
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.
right, that'll also break some existing tests but we should do that nevertheless
C does not allow casting of struct types by value, so we can follow this behaviour in BPFtrace. Some existing semantic analyser tests used casting to struct types, so they were changed to use pointer casts instead.
11d9380
to
867f68f
Compare
Updated to block both casts from and to struct types. |
C does not allow casting struct types by value, so we should do the same in BPFtrace.
Resolves #1869.
Checklist
docs/reference_guide.md
CHANGELOG.md