[clang] Avoid accessing unset optional, workaround for #100095 (PR #100408)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 24 09:42:32 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Alexander Kornienko (alexfh)

<details>
<summary>Changes</summary>

This is not a proper fix, but enables Clang to continue working with more libc++ runtime checks enabled.

---
Full diff: https://github.com/llvm/llvm-project/pull/100408.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+3-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index b7b857ebf804b..db7f233dcef73 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -951,9 +951,11 @@ class PackDeductionScope {
 
     // Skip over the pack elements that were expanded into separate arguments.
     // If we partially expanded, this is the number of partial arguments.
+    // FIXME: `&& FixedNumExpansions` is a workaround for UB described in
+    // https://github.com/llvm/llvm-project/issues/100095
     if (IsPartiallyExpanded)
       PackElements += NumPartialPackArgs;
-    else if (IsExpanded)
+    else if (IsExpanded && FixedNumExpansions)
       PackElements += *FixedNumExpansions;
 
     for (auto &Pack : Packs) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/100408


More information about the cfe-commits mailing list