Skip to content

bpo-29939: suppress compiler warnings in _ctypes_test #902

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 1 commit into from
Mar 31, 2017

Conversation

benjaminp
Copy link
Contributor

e.g.: _ctypes_test.c:53:42: warning: parameter ‘in’ set but not used [-Wunused-but-set-parameter]

e.g.: _ctypes_test.c:53:42: warning: parameter ‘in’ set but not used [-Wunused-but-set-parameter]
@serhiy-storchaka serhiy-storchaka requested a review from vsajip March 30, 2017 06:32
@serhiy-storchaka serhiy-storchaka changed the title suppress compiler warnings in _ctypes_test bpo-29939: suppress compiler warnings in _ctypes_test Mar 30, 2017
Copy link
Member

@vsajip vsajip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my system, at least, you can avoid the warning with just the simple:

    (void) in; /* avoid compiler warning */
    in.first = 0x0badf00d;
    in.second = 0x0badf00d;
    in.third = 0x0badf00d;

in the body of the function. Any reason that isn't preferable?

@brettcannon brettcannon added the type-feature A feature request or enhancement label Mar 30, 2017
@benjaminp
Copy link
Contributor Author

The main advantage is that it forces the compiler to generate code to write the struct argument, which I gather is part of the reason for the test. If you don't care, you might as well remove the assignments in the body of the function—you can bet the compiler will with the current code—and avoid the warnings in the first place.

@vsajip
Copy link
Member

vsajip commented Mar 31, 2017

Interesting. Before I put in the fix which this test exercises, I added this test, and it failed - indicating that the compiler was generating the code to write to the struct argument. After I put in the fix, the test started passing. Perhaps I've missed something there.

If you are finding that the compiler optimises out all the assignments, what compiler version/compiler flags/architecture are you using? It would be useful to know. My testing was done with Ubuntu 16.04 x86_64 with stock gcc.

@benjaminp
Copy link
Contributor Author

$ cat test.c
typedef struct {
    unsigned long first;
    unsigned long second;
    unsigned long third;
} Test;

int example(Test in) {
    in.first = 0x0badf00d;
    in.second = 0x0badf00d;
    in.third = 0x0badf00d;
}
$ gcc -O2 -S test.c
$ cat test.s
	.file	"test.c"
	.text
	.p2align 4,,15
	.globl	example
	.type	example, @function
example:
.LFB0:
	.cfi_startproc
	rep ret
	.cfi_endproc
.LFE0:
	.size	example, .-example
	.ident	"GCC: (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005"
	.section	.note.GNU-stack,"",@progbits

@vsajip
Copy link
Member

vsajip commented Mar 31, 2017

Can't argue with that :-) I'm probably mis-remembering what happened when I did the test.

@vsajip vsajip merged commit 164d30e into master Mar 31, 2017
@vsajip vsajip deleted the benjamin-ctypes-warnings branch March 31, 2017 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants