[llvm-bugs] [Bug 33755] New: thread safety analysis: attribute acquire_capability on lock function incorrectly causes error

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 11 21:33:06 PDT 2017


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

            Bug ID: 33755
           Summary: thread safety analysis: attribute acquire_capability
                    on lock function incorrectly causes error
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: danielgb at au1.ibm.com
                CC: llvm-bugs at lists.llvm.org

$ ~/clang/bin/clang -Werror=thread-safety -c ~/clang-tsa-test.c
/home/dan/clang-tsa-test.c:16:1: error: expecting mutex 'that' to be held at
the end of function [-Werror,-Wthread-safety-analysis]
}
^
/home/dan/clang-tsa-test.c:10:5: note: mutex acquired here
int mysql_mutex_lock(
    ^
1 error generated.


$ cat ~/clang-tsa-test.c

#include <pthread.h>

struct st_mysql_mutex
{
  pthread_mutex_t m_mutex;
};

typedef struct st_mysql_mutex __attribute((capability("mutex"))) mysql_mutex_t;

int mysql_mutex_lock(
  mysql_mutex_t *that
  , const char *src_file, unsigned int src_line
  ) __attribute((acquire_capability(*that)))
{
    return pthread_mutex_lock(&that->m_mutex);
}


$ ~/clang/bin/clang --version
clang version 5.0.0 (llvm-clang.git 79a6eca386d468058b31e2d4f54b1b736a12f558)
(llvm.git 31f450353208e4d108fff264a2eba433758a0709)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/dan/clang/bin

Older deprecated attributes also fails:

$ cat ~/clang-tsa-test2.c

#include <pthread.h>

struct st_mysql_mutex
{
  pthread_mutex_t m_mutex;
};

typedef struct st_mysql_mutex __attribute((capability("mutex"))) mysql_mutex_t;

int mysql_mutex_lock(
  mysql_mutex_t *that
  , const char *src_file, unsigned int src_line
  ) __attribute((exclusive_lock_function(*that)))
{
    return pthread_mutex_lock(&that->m_mutex);
}
~/clang/bin/clang -Werror=thread-safety -c ~/clang-tsa-test2.c
/home/dan/clang-tsa-test.c:16:1: error: expecting mutex 'that' to be held at
the end of function [-Werror,-Wthread-safety-analysis]
}
^
/home/dan/clang-tsa-test.c:10:5: note: mutex acquired here
int mysql_mutex_lock(
    ^
1 error generated.

-- 
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/20170712/2dcd7878/attachment.html>


More information about the llvm-bugs mailing list