[all-commits] [llvm/llvm-project] 87cbea: [openmp][cmake][NFCI] Avoid non-eval uses of ${var...

Michael Kruse via All-commits all-commits at lists.llvm.org
Mon Mar 2 04:21:57 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 87cbea6cdc9a55c1fda2d83820d0d81f314868a7
      https://github.com/llvm/llvm-project/commit/87cbea6cdc9a55c1fda2d83820d0d81f314868a7
  Author: Michael Kruse <llvm-project at meinersbur.de>
  Date:   2026-03-02 (Mon, 02 Mar 2026)

  Changed paths:
    M openmp/cmake/modules/LibompHandleFlags.cmake
    M openmp/cmake/modules/LibompUtils.cmake
    M openmp/docs/CMakeLists.txt
    M openmp/libompd/src/CMakeLists.txt
    M openmp/runtime/CMakeLists.txt
    M openmp/runtime/cmake/LibompExports.cmake
    M openmp/runtime/cmake/LibompMicroTests.cmake
    M openmp/runtime/cmake/config-ix.cmake
    M openmp/runtime/src/CMakeLists.txt
    M openmp/tools/omptest/CMakeLists.txt

  Log Message:
  -----------
  [openmp][cmake][NFCI] Avoid non-eval uses of ${var} (#182267)

When using

    set(var "Example")
    if (${var})

CMake will first resolve the if-argument to

    if (Example)

And what then happens depends on the existance of a variable with the
name "Example":

1. If instead of "Example", a truth constant is used ("TRUE", "FALSE",
   "ON", "OFF", "", "-NOTFOUND" ...), it is prioritized
   (https://cmake.org/cmake/help/latest/command/if.html#constant)

2. If a variable with the name "Example" exists: Use the truthiness of
   its content
   (https://cmake.org/cmake/help/latest/command/if.html#variable)

3. Otherwise, it is false-y

That is, the the result of the conditional does not only depend on the
content of `var`, but also some other variable. This is usually
unintended and leads to problems such as addressed with #154537. The
only case where this is intended is when passing an expression to be
evaluated such as with `pythonize_bool`, `append_if` and
`libomp_append`. In all other cases, using `${var}` without quotes is a
pattern to be avoided.

Remark:
If `${var}` is not one of the values considered a [truthiness
constant](https://cmake.org/cmake/help/latest/command/if.html#constant),
the result of `if (var)` and `if ("${var}")` is different:

* `if (var)` is true-ish
  (https://cmake.org/cmake/help/latest/command/if.html#variable)

* `if ("Example")` and therefore `if ("${var}")` are false-y
  (https://cmake.org/cmake/help/latest/command/if.html#string)

In this PR I am preferring `if (var)` over `if ("${var}")` because has
less clutter, resembles Python's behaviour, and problably what most
users are expecting, even though `if (${var})` in most cases would
evaluate to false-y because a variable does not exist. This ambiguity
does not exist for STREQUAL and MATCHES.



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