ernie-research/MEnvBench huggingface dataset:
Repository: halide/Halide (C++)

Issue:
Apparent write beyond end of buffer in jit-compiled code
The following code writes beyond the end of Buffer r0 inside the JIT-compiled code. Given the schedule, I believe the minimum viable output size is 1024 + 16, starting at -1, not 1024 starting at zero, so it should be failing a bounds check, but it's not.

```
    Var x;
    const int size = 1024;
    Func h;
    h(x) = {0, 0};
    RDom r(0, size);
    h(r) = {h(r - 1)[0], 0};

    Var xo, xi;
    h.split(x, xo, xi, 16, TailStrategy::RoundUp);

    Buffer<int> r0(size);
    Buffer<int> r1(size);
    h.realize({r0, r1});
```



Fix (patch):
diff --git a/src/AddImageChecks.cpp b/src/AddImageChecks.cpp
index e9ca8ae25be9..72f2596fe12b 100644
--- a/src/AddImageChecks.cpp
+++ b/src/AddImageChecks.cpp
@@ -106,11 +106,21 @@ class TrimStmtToPartsThatAccessBuffers : public IRMutator {
     using IRMutator::visit;
 
     Expr visit(const Call *op) override {
-        touches_buffer |= (buffers.count(op->name) > 0);
+        touches_buffer |=
+            (buffers.count(op->name) > 0) ||
+            (buffers.count(op->name + "." + std::to_string(op->value_index)));
+        // Output Tuple params are in the buffers map under their qualified
+        // tuple name, not the Func name.
         return IRMutator::visit(op);
     }
     Stmt visit(const Provide *op) override {
-        touches_buffer |= (buffers.find(op->name) != buffers.end());
+        if (op->values.size() == 1) {
+            touches_buffer |= (buffers.find(op->name) != buffers.end());
+        } else {
+            // It's a Tuple. Just check if the first Tuple component corresponds
+            // to an output buffer. If it does, they all do.
+            touches_buffer |= (buffers.find(op->name + ".0") != buffers.end());
+        }
         return IRMutator::visit(op);
     }
     Expr visit(const Variable *op) override {
Repository: halide/Halide (C++)

Issue:
Internal error during partition loops
A simple repro
```cpp
    Func input("input");
    Func local_sum("local_sum");
    Func blurry("blurry");
    Var x("x"), y("y");
    input(x, y) = 2 * x + 5 * y;
    RDom r(-2, 5, -2, 5);
    local_sum(x, y) = 0;
    local_sum(x, y) += input(x + r.x, y + r.y);
    blurry(x, y) = cast<int32_t>(local_sum(x, y) / 25);
    Var yo("yo"), yi("yi"), xo("xo"), xi("xi"), yo_x_f("yo_x_f"), yo_x_fo("yo_x_fo"), yo_x_fi("yo_x_fi");
    blurry.split(y,yo, yi, 2, TailStrategy::RoundUp).fuse(yo, x, yo_x_f).vectorize(yi).split(yo_x_f, yo_x_fo, yo_x_fi, 2, TailStrategy::Predicate).reorder(yo_x_fo, yo_x_fi, yi);
    input.split(y, yo, yi, 2, TailStrategy::PredicateStores).fuse(yo, x, yo_x_f).vectorize(yi).split(yo_x_f, yo_x_fo, yo_x_fi, 2, TailStrategy::Predicate).reorder(yo_x_fo, yo_x_fi, yi);
    blurry.store_root();
    input.compute_at(blurry, yi);
    Pipeline p({blurry});
    Buffer<int> buf = p.realize({32, 32});
```

Triggers:
```
Internal Error at /home/xuanda/dev/Serializer/Halide/src/PartitionLoops.cpp:276 triggered by user code at : Condition failed: s.condition.type().is_scalar(): (ramp((((((input.s0.y.yo.yo_x_f.yo_x_fo*2) + input.s0.y.yo.yo_x_f.yo_x_fi) % ((blurry.extent.1 + 5)/2))*2) + blurry.min.1) + -4, 1, 2) <= x2((((blurry.extent.1 + -1)/2)*2) + blurry.min.1))
```



Fix (patch):
diff --git a/src/IR.cpp b/src/IR.cpp
index 244d142cfb60..bf53aaac476c 100644
--- a/src/IR.cpp
+++ b/src/IR.cpp
@@ -574,6 +574,8 @@ Stmt IfThenElse::make(Expr condition, Stmt then_case, Stmt else_case) {
     internal_assert(condition.defined() && then_case.defined()) << "IfThenElse of undefined\n";
     // else_case may be null.
 
+    internal_assert(condition.type().is_scalar()) << "IfThenElse with vector condition\n";
+
     IfThenElse *node = new IfThenElse;
     node->condition = std::move(condition);
     node->then_case = std::move(then_case);
diff --git a/src/PartitionLoops.cpp b/src/PartitionLoops.cpp
index d3b296dc0165..477b91173f19 100644
--- a/src/PartitionLoops.cpp
+++ b/src/PartitionLoops.cpp
@@ -263,7 +263,7 @@ class FindSimplifications : public IRVisitor {
         }
         condition = remove_likelies(condition);
         Simplification s = {condition, std::move(old), std::move(likely_val), std::move(unlikely_val), true};
-        if (s.condition.type().is_vector()) {
+        while (s.condition.type().is_vector()) {
             s.condition = simplify(s.condition);
             if (const Broadcast *b = s.condition.as<Broadcast>()) {
                 s.condition = b->value;
diff --git a/src/Simplify_Stmts.cpp b/src/Simplify_Stmts.cpp
index 5be05e42e6c6..6a8e53ccfa73 100644
--- a/src/Simplify_Stmts.cpp
+++ b/src/Simplify_Stmts.cpp
@@ -328,6 +328,10 @@ Stmt Simplify::visit(const Store *op) {
 
     const Load *load = value.as<Load>();
     const Broadcast *scalar_pred = predicate.as<Broadcast>();
+    if (scalar_pred && !scalar_pred->value.type().is_scalar()) {
+        // Nested vectorization
+        scalar_pred = nullptr;
+    }
 
     ModulusRemainder align = ModulusRemainder::intersect(op->alignment, base_info.alignment);
Repository: shader-slang/slang (C++)

Issue:
Slang reflection not returning function name
In Slang 2025.13.2, with this code:

```
public interface IBase
{
    public void step(inout float f);
}

public struct Impl : IBase
{
    public void step(inout float f)
    {
        f += 1.0f;
    }
}
```

When I load the module, ask for the layout, get `findTypeByName("Impl")` and then `findFunctionByNameInType` on `step`, I get a `slang::FunctionReflection` that returns `NULL` for `getName()`




Discussion: @copilot can you try to create a repro unit test, similar to `tools\slang-unit-test\unit-test-find-type-by-name.cpp`, and run it with `slang-test slang-unit-test-tool/findFunctionByName`, and then fix the bug.
The root cause of this is that if the lookup result is overloaded, then we can't return a name. This can be fixed easily by returning the name of the first overload candidate in such case.



Fix (patch):
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp
index 95dcc62497..c5d39859e7 100644
--- a/source/slang/slang-reflection-api.cpp
+++ b/source/slang/slang-reflection-api.cpp
@@ -3471,10 +3471,21 @@ SLANG_API SlangReflectionDecl* spReflectionFunction_asDecl(SlangReflectionFuncti
 SLANG_API char const* spReflectionFunction_GetName(SlangReflectionFunction* inFunc)
 {
     auto func = convertToFunc(inFunc);
-    if (!func)
-        return nullptr;
+    if (func)
+        return getText(func.getDecl()->getName()).getBuffer();
 
-    return getText(func.getDecl()->getName()).getBuffer();
+    // If convertToFunc failed, this might be an overloaded function.
+    // Try to get the name from the first overload candidate.
+    auto overloadedFunc = convertToOverloadedFunc(inFunc);
+    if (overloadedFunc && overloadedFunc->lookupResult2.items.getCount() > 0)
+    {
+        auto firstOverload = overloadedFunc->lookupResult2.items[0].declRef;
+        if (auto funcDeclRef = firstOverload.as<FunctionDeclBase>())
+        {
+            return getText(funcDeclRef.getDecl()->getName()).getBuffer();
+        }
+    }
+    return nullptr;
 }
 
 SLANG_API SlangReflectionType* spReflectionFunction_GetResultType(SlangReflectionFunction* inFunc)
Repository: hsutter/cppfront (C++)

Issue:
[BUG] `is` type for `std::optional` can return unexpected results
**Describe the bug**
An expression testing if a `std::optional` is a type can return unexpected results, depending on whether the `optional`'s type is convertible to the target type. (I'm assuming this behaviour is unintended.)

**To Reproduce**
Run cppfront on the following and then compile with a C++ compiler:
```cpp
main: () -> int = {
    o: std::optional<int> = 5;
    if o is int {
        std::cout << "int!\n";
    }
    if o is bool {
        std::cout << "bool!\n";
    }
    if o is float {
        std::cout << "float!\n";
    }
    if o is std::string {
        std::cout << "std::string!\n";
    }
    return 0;
}
```
The output is:
```
int!
bool!
float!
```
[Repro](https://cpp2.godbolt.org/z/GravGeq8f) on Godbolt.

I think this behaviour is due to this cast:
https://github.com/hsutter/cppfront/blob/ddde3d833bec373081a3c0f419250f8e8b553805/include/cpp2util.h#L2042

CC @filipsajdak 



Fix (patch):
diff --git a/include/cpp2util.h b/include/cpp2util.h
index 6b9d48894..49e0c72c8 100644
--- a/include/cpp2util.h
+++ b/include/cpp2util.h
@@ -2102,10 +2102,8 @@ constexpr auto is( X const& x ) -> bool {
     if (!x.has_value()) {
         return std::same_as<T, empty>;
     }
-    if constexpr (requires { static_cast<const T&>(*x);}) {
-        return true;
-    }
-    return false;
+    return std::same_as<T, typename X::value_type> 
+        || std::derived_from<std::remove_pointer_t<typename X::value_type>, std::remove_pointer_t<T>>;
 }
 
 //  is Value
Repository: hsutter/cppfront (C++)

Issue:
[BUG] _template-head_ missing from variable template definition
**Title**: _template-head_ missing from variable template definition.

**Minimal reproducer** (<https://godbolt.org/z/Yn6zav1Gr>):
```Cpp2
v0: <V: _> int = 0;
main: () -> int = {
  return v0<:int = 0>;
}
```

**Commands**:
```bash
cppfront x.cpp2
clang++17 -std=c++2b -stdlib=libc++ -I $CPPFRONT_INCLUDE_DIR x.cpp
```

**Expected result**:
```C++
template<auto V> int v0 {0}; 
```

**Actual result and error**:

<details><summary>Generated Cpp1.</summary>

```C++
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

#line 1 "/app/main.cpp2"
template<auto V> extern int v0;
[[nodiscard]] auto main() -> int;
  

//=== Cpp2 function definitions =================================================

#line 1 "/app/main.cpp2"
int v0 {0}; 
[[nodiscard]] auto main() -> int{
  return v0<int{0}>; 
}
```

</details>

```output
main.cpp2:1:5: error: redefinition of 'v0' as different kind of symbol
int v0 {0}; 
    ^
main.cpp2:1:29: note: previous definition is here
template<auto V> extern int v0;
                            ^
1 error generated.
```



Fix (patch):
diff --git a/source/cppfront.cpp b/source/cppfront.cpp
index 1bad85a53..70b19ff6c 100644
--- a/source/cppfront.cpp
+++ b/source/cppfront.cpp
@@ -5066,6 +5066,7 @@ class cppfront
             n.template_parameters
             && (
                 printer.get_phase() <  printer.phase2_func_defs
+                || n.is_object()
                 || (
                     n.is_function()
                     && n.has_name()     // only if it is not unnambed function aka lambda
Repository: hsutter/cppfront (C++)

Issue:
[BUG] `Wshorten-64-to-32` clang warning when using range `0 ..< vector.size()`
**Describe the bug**
Clang produces a `Wshorten-64-to-32` warning with a `cpp2::range` when it is initialised with an integer literal as the first member and an expression producing a `size_t`/`size_type` as the second member.

**To Reproduce**
Run cppfront on the following code and then compile with clang with `-Wconversion`:
```cpp
main: () = {
    v: std::vector = (11, 22, 33);

    for 0 ..< v.size() do (i) {    // Warning
        v[i]++;
    }
    std::println("v: {}", v);

    for 0uz ..< v.size() do (i) {  // No warning with `uz`
        v[i]++;
    }
    std::println("v: {}", v);
}
```
The warning is:
```
warning: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'const std::type_identity_t<int>' (aka 'const int') [-Wshorten-64-to-32]
```
[Repro](https://cpp2.godbolt.org/z/Gjh89Pboj) on Godbolt

This is because the `cpp2::range` constructor deduces the type from only the first parameter:
```cpp
range(
    T const&                       f,
    std::type_identity_t<T> const& l,
    bool                           include_last = false
)
```




Discussion: It should probably deduce to the bigger of the two, if possible.
> It should probably deduce to the bigger of the two, if possible.

Yes, in my PR I use `std::common_type` and it appears to do just that.



Fix (patch):
diff --git a/include/cpp2util.h b/include/cpp2util.h
index 90ed49bfc..ed07d1349 100644
--- a/include/cpp2util.h
+++ b/include/cpp2util.h
@@ -746,6 +746,11 @@ concept valid_custom_is_operator = predicate_member_fun<X, F, &F::op_is>
                         || brace_initializable_to<X, argument_of_op_is_t<F>> 
                       );
 
+template <typename T, typename U>
+concept has_common_type = requires (T t, U u) {
+    typename std::common_type_t<T, U>;
+};
+
 //-----------------------------------------------------------------------
 //
 //  General helpers
@@ -2437,6 +2442,19 @@ class range
         }
     }
 
+    //  When the first & last types are different, use a CTAD deduction guide
+    //  to find the `std::common_type` for them, if one exists. See below
+    //  after the class definition for the deduction guide.
+    template <typename U>
+        requires has_common_type<T, U>
+    range(
+        T const& f,
+        U const& l,
+        bool     include_last = false
+    )
+        : range(f, l, include_last)
+    {}
+
     class iterator 
     {
         TT first = T{};
@@ -2572,6 +2590,16 @@ class range
     }
 };
 
+//  CTAD deduction guide for the `range` constructor that takes two different types.
+//  Deduces the `std::common_type` for them, if one exists.
+template <typename T, typename U>
+    requires has_common_type<T, U>
+range(
+    T const& f,
+    U const& l,
+    bool     include_last = false
+) -> range<std::common_type_t<T, U>>;
+
 template<typename T>
 constexpr auto contains(range<T> const& r, T const& t)
     -> bool
Repository: hsutter/cppfront (C++)

Issue:
[BUG] UTF-32 string literals failure
Compile failure for `U` prefix (uppercase) on string literals.

I've tried to compile the following code with [godbolt](https://godbolt.org/noscript/cpp2_cppfront):

```
main: () = {
    x := U"text";
}
```

It should generate the following C++1 code:

```
auto main() -> int{
    auto x {U"text"}; 
}
```

But it fails with the following error:

```
# Compilation provided by Compiler Explorer at https://godbolt.org/
<Compilation failed>
# Compiler exited with result code 1
Standard out:
<source>...
Standard error:

example.cpp2(2,11): error: ill-formed initializer (at '"text"')
example.cpp2(1,12): error: ill-formed initializer (at '{')
example.cpp2(1,1): error: unexpected text at end of Cpp2 code section (at 'main')
example.cpp2(1,0): error: parse failed for section starting here
```

Anyway, I hope there was a plan to get rid of all those unicode prefixes :blush:


Discussion: @msadeqhe, thanks for spotting that - fixed in #299



Fix (patch):
diff --git a/source/lex.h b/source/lex.h
index c43551cbb..7576dffc7 100644
--- a/source/lex.h
+++ b/source/lex.h
@@ -373,7 +373,9 @@ auto expand_string_literal(
     ++pos;
     auto current_start = pos;   // the current offset before which the string has been added to ret
 
-    auto parts = string_parts{"\"", "\"", string_parts::on_both_ends};
+    auto parts = string_parts{std::string(text.substr(0, current_start)), // begin sequence ", U", u8" depends on the string type 
+                              "\"", // end sequence
+                              string_parts::on_both_ends}; // add opening and closing sequence to generated string
 
     //  Now we're on the first character of the string itself
     for (
Repository: ninja-build/ninja (C++)

Issue:
depfile consisting exclusively of newlines causes an error
I'm currently working on adding support for using depfiles with Vala compiler in meson. I got it mostly working - however, if files just so happen to have no dependencies (unlikely in real projects but happens for two of meson's tests), `valac` generates a depfile consisting exclusively of two newline characters (I've double-checked with a hex editor that it's really just that).

Ninja fails to parse such a file with the following error:

```
expected ':' in depfile
```



Fix (patch):
diff --git a/src/depfile_parser.cc b/src/depfile_parser.cc
index 98fba2eda6..7ce7290614 100644
--- a/src/depfile_parser.cc
+++ b/src/depfile_parser.cc
@@ -54,6 +54,7 @@ bool DepfileParser::Parse(string* content, string* err) {
   bool have_target = false;
   bool parsing_targets = true;
   bool poisoned_input = false;
+  bool is_empty = true;
   while (in < end) {
     bool have_newline = false;
     // out: current output point (typically same as in, but can fall behind
@@ -335,6 +336,7 @@ bool DepfileParser::Parse(string* content, string* err) {
     }
 
     if (len > 0) {
+      is_empty = false;
       StringPiece piece = StringPiece(filename, len);
       // If we've seen this as an input before, skip it.
       std::vector<StringPiece>::iterator pos = std::find(ins_.begin(), ins_.end(), piece);
@@ -363,7 +365,7 @@ bool DepfileParser::Parse(string* content, string* err) {
       poisoned_input = false;
     }
   }
-  if (!have_target) {
+  if (!have_target && !is_empty) {
     *err = "expected ':' in depfile";
     return false;
   }
diff --git a/src/depfile_parser.in.cc b/src/depfile_parser.in.cc
index 75ba98227b..4b5f5fe4c1 100644
--- a/src/depfile_parser.in.cc
+++ b/src/depfile_parser.in.cc
@@ -53,6 +53,7 @@ bool DepfileParser::Parse(string* content, string* err) {
   bool have_target = false;
   bool parsing_targets = true;
   bool poisoned_input = false;
+  bool is_empty = true;
   while (in < end) {
     bool have_newline = false;
     // out: current output point (typically same as in, but can fall behind
@@ -171,6 +172,7 @@ bool DepfileParser::Parse(string* content, string* err) {
     }
 
     if (len > 0) {
+      is_empty = false;
       StringPiece piece = StringPiece(filename, len);
       // If we've seen this as an input before, skip it.
       std::vector<StringPiece>::iterator pos = std::find(ins_.begin(), ins_.end(), piece);
@@ -199,7 +201,7 @@ bool DepfileParser::Parse(string* content, string* err) {
       poisoned_input = false;
     }
   }
-  if (!have_target) {
+  if (!have_target && !is_empty) {
     *err = "expected ':' in depfile";
     return false;
   }
Repository: KratosMultiphysics/Kratos (C++)

Issue:
[GeoMechanicsApplication] Improve the out-of-range check for Poisson's ratio
The range check for Poisson's ratio (an input parameter) is rather awkward and probably incorrect, see [this comment](https://github.com/KratosMultiphysics/Kratos/pull/11953#discussion_r1453196033). As indicated by the comment, Poisson's ratio should be in the range [-1.0, 0.5>.



Fix (patch):
diff --git a/applications/GeoMechanicsApplication/custom_constitutive/linear_elastic_law.cpp b/applications/GeoMechanicsApplication/custom_constitutive/linear_elastic_law.cpp
index cac5d93772a0..72eba7ee1e21 100644
--- a/applications/GeoMechanicsApplication/custom_constitutive/linear_elastic_law.cpp
+++ b/applications/GeoMechanicsApplication/custom_constitutive/linear_elastic_law.cpp
@@ -155,16 +155,20 @@ int GeoLinearElasticLaw::Check(const Properties&   rMaterialProperties,
                                const ProcessInfo&  rCurrentProcessInfo) const
 {
     KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(YOUNG_MODULUS))
-        << "YOUNG_MODULUS is not available in material parameters" << std::endl;
+        << "YOUNG_MODULUS is not available in the parameters of material "
+        << rMaterialProperties.Id() << "." << std::endl;
     KRATOS_ERROR_IF(rMaterialProperties[YOUNG_MODULUS] <= 0.0)
-        << "YOUNG_MODULUS is invalid value " << std::endl;
+        << "The value of YOUNG_MODULUS (" << rMaterialProperties[YOUNG_MODULUS]
+        << ") should be positive in material " << rMaterialProperties.Id() << "." << std::endl;
 
     KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(POISSON_RATIO))
-        << "POISSON_RATIO is not available in material parameters" << std::endl;
+        << "POISSON_RATIO is not available in the parameters of material "
+        << rMaterialProperties.Id() << "." << std::endl;
 
-    const double& nu = rMaterialProperties[POISSON_RATIO];
-    KRATOS_ERROR_IF((nu > 0.499 && nu < 0.501) || (nu < -0.999 && nu > -1.01))
-        << "POISSON_RATIO has invalid value " << std::endl;
+    const auto nu = rMaterialProperties[POISSON_RATIO];
+    KRATOS_ERROR_IF(nu < -1.0 || nu >= 0.5) << "The value of POISSON_RATIO (" << nu
+                                            << ") should be in the range [-1.0, 0.5> in material "
+                                            << rMaterialProperties.Id() << "." << std::endl;
 
     return 0;
 }
Repository: luau-lang/luau (C++)

Issue:
Include a useful `definitionModuleName` for types originating from definitions file
Right now, when loading in types from a definitions file, the relevant `definitionModuleName` for the FunctionType/ClassType etc. is empty. This is because the SourceModule passed to `check()` in `loadDefinitions` has no module name set.

It would be useful to have this information populated to understand where a type comes from (and permit operations such as Go To Declaration and documentation comments)



Fix (patch):
diff --git a/Analysis/src/Frontend.cpp b/Analysis/src/Frontend.cpp
index 710e36993..125f24579 100644
--- a/Analysis/src/Frontend.cpp
+++ b/Analysis/src/Frontend.cpp
@@ -38,6 +38,7 @@ LUAU_FASTFLAGVARIABLE(DebugLuauLogSolverToJson, false)
 LUAU_FASTFLAGVARIABLE(DebugLuauReadWriteProperties, false)
 LUAU_FASTFLAGVARIABLE(LuauTypecheckLimitControls, false)
 LUAU_FASTFLAGVARIABLE(CorrectEarlyReturnInMarkDirty, false)
+LUAU_FASTFLAGVARIABLE(LuauDefinitionFileSetModuleName, false)
 
 namespace Luau
 {
@@ -165,6 +166,11 @@ LoadDefinitionFileResult Frontend::loadDefinitionFile(GlobalTypes& globals, Scop
     LUAU_TIMETRACE_SCOPE("loadDefinitionFile", "Frontend");
 
     Luau::SourceModule sourceModule;
+    if (FFlag::LuauDefinitionFileSetModuleName)
+    {
+        sourceModule.name = packageName;
+        sourceModule.humanReadableName = packageName;
+    }
     Luau::ParseResult parseResult = parseSourceForModule(source, sourceModule, captureComments);
     if (parseResult.errors.size() > 0)
         return LoadDefinitionFileResult{false, parseResult, sourceModule, nullptr};