-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Use using instead of typedef [kdtree, keypoints, octree] #3122
Use using instead of typedef [kdtree, keypoints, octree] #3122
Conversation
keypoints/src/brisk_2d.cpp
Outdated
@@ -1669,7 +1669,7 @@ pcl::keypoints::brisk::Layer::halfsample ( | |||
// compute horizontal pairwise average and store | |||
p_dest_char = reinterpret_cast<unsigned char*> (p_dest); | |||
#ifdef __GNUC__ | |||
typedef unsigned char __attribute__ ((__may_alias__)) UCHAR_ALIAS; | |||
using UCHAR_ALIAS = unsigned char; |
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.
Any idea what did this attribute do?
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.
I have the feeling it likely disables aliasing warnings that will be triggered by this.
pcl/keypoints/src/brisk_2d.cpp
Line 1678 in 2f0dc49
const UCHAR_ALIAS* result = reinterpret_cast<const UCHAR_ALIAS*> (&result1); |
More on the topic:
https://stackoverflow.com/questions/6313050/gcc-how-to-use-attribute-may-alias-properly-to-avoid-derefencing-type
https://en.wikipedia.org/wiki/Aliasing_(computing)#Conflicts_with_optimization
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.
Let's maybe leave the typedef here?
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.
I'm surprised the same logic can't be expressed with using
.
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.
Maybe it could. But frankly speaking... I have no desire to study this question. Getting rid of each and every typedef
is a no-goal for us, so leaving as-is is the safest option I think.
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.
@SunBlack according to this page, using
alias should look like:
using identifier attr(optional) = type-id
That is, attributes come before equals sign. Right now attributes are after equals and the thing still compiles, however we don't know whether it works as expected. I'd suggest we keep typedef
to avoid potential troubles.
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.
You are right, my code is not correct. I played now a bit with it by using a aliasing example from here. I adjusted the code the to use aliasing typedef, see here.
Result:
typedef float FLOAT_ALIAS;
and using FLOAT_ALIAS = __attribute__ ((__may_alias__)) float;
are producing:
foo(float*, int*): # @foo(float*, int*)
mov dword ptr [rsi], 1
mov dword ptr [rdi], 0
mov eax, 1
ret
typedef float __attribute__ ((__may_alias__)) FLOAT_ALIAS;
and using FLOAT_ALIAS __attribute__ ((__may_alias__)) = float;
are producing:
foo(float*, int*): # @foo(float*, int*)
mov dword ptr [rsi], 1
mov dword ptr [rdi], 0
mov eax, dword ptr [rsi]
ret
@taketwo I believed attr
in using identifier attr(optional) = type-id
is only for new attributes like [[deprecated]]
, but are right :).
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.
Just to add a note: I don't believe we need aliasing here anywhere, because we are just reading value of result1
(so nothing to optimize there).
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.
👍 thanks for researching assembly, good to know!
2f0dc49
to
cc5a3bc
Compare
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.
As per inline comment, according to this page, using
alias should look like:
using identifier attr(optional) = type-id
That is, attributes come before equals sign. Right now attributes are after equals and the thing still compiles, however we don't know whether it works as expected. I'd suggest we keep typedef
to avoid potential troubles.
…ernize-use-using' -fix
cc5a3bc
to
249b5b8
Compare
Changes are done by:
run-clang-tidy -header-filter='.' -checks='-,modernize-use-using' -fix