Issue 143325
Summary relocation diagnostics asserts in response to code that is broken for unrelated reasons #awesome
Labels good first issue
Assignees cor3ntin
Reporter ojhunt
    I made an error in one of my test cases and got a crash due to a null value. After much confusion I realized the problem is actually that I had redefined the same struct multiple times, and that's what caused the unexpected state.

The test case:

```cpp
struct Foo  {
  Foo(const Foo&);
  ~Foo();
};

struct Foo {
  Foo();
  int;
};

struct Wrapper {
  union {
    Foo p;
  } u;
};
static_assert(__builtin_is_cpp_trivially_relocatable(Wrapper));
```

The assertion is triggered under `DiagnoseNonTriviallyRelocatableReason` in this code:
```cpp
  if (!D->hasSimpleMoveConstructor() && !D->hasSimpleCopyConstructor()) {
    const auto *Decl = cast<CXXConstructorDecl>(
        LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false));
    if (Decl && Decl->isUserProvided())
 SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
          << diag::TraitNotSatisfiedReason::UserProvidedCtr
          << Decl->isMoveConstructor() << Decl->getSourceRange();
  }
```

The issue is the `cast< CXXConstructorDecl >` as `LookupSpecialMemberFromXValue` can return null. The `cast<>` is followed by a null check so it's presumably expected that `LookupSpecialMemberFromXValue` returns null, in which case the fix is likely just to replace `cast` with `cast_or_null`. If it's expected that the cast itself may fail then I assume there's `dyn_cast_or_null` that should be used.


_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to