[llvm-bugs] [Bug 51865] New: Variable is incorrectly marked as "set but not used" when used with the __cleanup__() attribute

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 15 01:13:25 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51865

            Bug ID: 51865
           Summary: Variable is incorrectly marked as "set but not used"
                    when used with the __cleanup__() attribute
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: frantisek at sumsal.cz
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Hello,

Yesterday I came across a possible issue in clang-13 when trying to rebuild[0]
the systemd codebase with one of the nightly[1] LLVM builds. After minimizing
the reproducer, the issue stems from a fact that clang incorrectly marks a
variable as "set but not used" if the variable is used only from the
__cleanup__() function:

Reproducer:
#include <stdio.h>

static void my_cleanup(char **test) {
    if (test)
        printf("my_cleanup: %s\n", *test);
}

int main(void) {
    __attribute__((__cleanup__(my_cleanup))) char *x = NULL;

    puts("Hello");
    x = "test";
    puts("World");

    return 0;
}

Expected behavior (clang-12):
# clang --version
clang version 12.0.1 (Fedora 12.0.1-1.fc34)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /bin
# clang -Wall -Wextra -Werror -o test test.c

Unexpected behavior (clang-13):
# clang-13 --version
Ubuntu clang version
13.0.0-++20210914062619+f6b09e394a5f-1~exp1~20210914043438.103
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
# clang-13 -Wall -Wextra -Werror -o test test.c
test.c:9:52: error: variable 'x' set but not used
[-Werror,-Wunused-but-set-variable]
    __attribute__((__cleanup__(my_cleanup))) char *x = NULL;
                                                   ^
1 error generated.


[0] https://github.com/systemd/systemd/pull/20738
[1] https://apt.llvm.org/

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210915/693ae05c/attachment.html>


More information about the llvm-bugs mailing list