public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "symbioticfemale at cumallover dot me" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/113769] New: GCC fails to warn of integer being used uninitialized
Date: Mon, 05 Feb 2024 14:07:17 +0000	[thread overview]
Message-ID: <bug-113769-4@http.gcc.gnu.org/bugzilla/> (raw)

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);
}

             reply	other threads:[~2024-02-05 14:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 14:07 symbioticfemale at cumallover dot me [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113769-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).