[all-commits] [llvm/llvm-project] 871038: Thread Safety Analysis: Fix pointer handling of va...

Marco Elver via All-commits all-commits at lists.llvm.org
Tue Jul 15 23:46:07 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 871038759afb491c16fb2cd14b78e51e410efbf3
      https://github.com/llvm/llvm-project/commit/871038759afb491c16fb2cd14b78e51e410efbf3
  Author: Marco Elver <elver at google.com>
  Date:   2025-07-16 (Wed, 16 Jul 2025)

  Changed paths:
    M clang/lib/Sema/AnalysisBasedWarnings.cpp
    M clang/test/SemaCXX/warn-thread-safety-analysis.cpp

  Log Message:
  -----------
  Thread Safety Analysis: Fix pointer handling of variables with deprecated attributes (#148974)

de10e44b6fe7 ("Thread Safety Analysis: Support warning on
passing/returning pointers to guarded variables") added checks for
passing pointer to guarded variables. While new features do not
necessarily need to support the deprecated attributes (`guarded_var`,
and `pt_guarded_var`), we need to ensure that such features do not cause
the compiler to crash.

As such, code such as this:

	struct {
	  int v __attribute__((guarded_var));
	} p;

	int *g() {
	  return &p.v;  // handleNoMutexHeld() with POK_ReturnPointer
	}

Would crash in debug builds with the assertion in handleNoMutexHeld()
triggering. The assertion is meant to capture the fact that this helper
should only be used for warnings on variables (which the deprecated
attributes only applied to).

To fix, the function handleNoMutexHeld() should handle all POK cases
that apply to variables explicitly, and produce a best-effort warning.

We refrain from introducing new warnings to avoid unnecessary code bloat
for deprecated features.

Fixes: https://github.com/llvm/llvm-project/issues/140330



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list