public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113769] New: GCC fails to warn of integer being used uninitialized
@ 2024-02-05 14:07 symbioticfemale at cumallover dot me
2024-02-05 14:22 ` [Bug c/113769] " symbioticfemale at cumallover dot me
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: symbioticfemale at cumallover dot me @ 2024-02-05 14:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113769
Bug ID: 113769
Summary: GCC fails to warn of integer being used uninitialized
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: symbioticfemale at cumallover dot me
Target Milestone: ---
// The "used uninitialized" warning is not produced on both GCC and Tiny
Compiler. Clang recognizes the error. (-Wall on all compilers). See line
comments for further explanation. The latest version of GCC I've tested with is
13.2.1.
// Version 1: With printf
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
pthread_rwlock_t necessary_lock = PTHREAD_RWLOCK_INITIALIZER;
void do_nothing(const void *value);
void do_nothing(const void *value)
{
printf("%p\n",value); // do anything on value other than (void) value
}
int main(void) {
pthread_rwlock_rdlock(&necessary_lock);
pthread_rwlock_unlock(&necessary_lock);
// Fun fact: remove either the pthread_rwlock_rdlock +
pthread_rwlock_unlock, or the printf in do_nothing, and GCC catches the lack of
initialization
uint32_t pos;
pos += 1;
do_nothing(&pos);
printf("%u\n",pos);
}
// Version 2: Without printf
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
pthread_rwlock_t necessary_lock = PTHREAD_RWLOCK_INITIALIZER;
void do_nothing(const void *value);
void do_nothing(const void *value)
{
(void) value;
}
int main(void) {
pthread_rwlock_rdlock(&necessary_lock);
pthread_rwlock_unlock(&necessary_lock);
// Fun fact: remove either the pthread_rwlock_rdlock +
pthread_rwlock_unlock, or the do_nothing function call, and GCC catches the
lack of initialization. Add a printf after do_nothing and GCC will also catch
it.
uint32_t pos;
pos += 1;
do_nothing(&pos);
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-05 16:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05 14:07 [Bug c/113769] New: GCC fails to warn of integer being used uninitialized symbioticfemale at cumallover dot me
2024-02-05 14:22 ` [Bug c/113769] " symbioticfemale at cumallover dot me
2024-02-05 14:25 ` redi at gcc dot gnu.org
2024-02-05 16:56 ` [Bug tree-optimization/113769] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).