Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,9 @@ void CGRecordLowering::calculateZeroInit() {
// Verify accumulateBitfields computed the correct storage representations.
void CGRecordLowering::checkBitfieldClipping(bool IsNonVirtualBaseType) const {
#ifndef NDEBUG
if (Context.getLangOpts().DebuggerSupport)
return;

auto ScissorOffset = calculateTailClippingOffset(IsNonVirtualBaseType);
auto Tail = CharUnits::Zero();
for (const auto &M : Members) {
Expand Down Expand Up @@ -1008,7 +1011,8 @@ void CGRecordLowering::insertPadding() {
if (!Member->Data)
continue;
CharUnits Offset = Member->Offset;
assert(Offset >= Size);
if (!Context.getLangOpts().DebuggerSupport)
assert(Offset >= Size);
// Insert padding if we need to.
if (Offset !=
Size.alignTo(Packed ? CharUnits::One() : getAlignment(Member->Data)))
Expand Down Expand Up @@ -1138,18 +1142,20 @@ CodeGenTypes::ComputeRecordLayout(const RecordDecl *D, llvm::StructType *Ty) {
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(D);

uint64_t TypeSizeInBits = getContext().toBits(Layout.getSize());
assert(TypeSizeInBits == getDataLayout().getTypeAllocSizeInBits(Ty) &&
"Type size mismatch!");
if (!Context.getLangOpts().DebuggerSupport)
assert(TypeSizeInBits == getDataLayout().getTypeAllocSizeInBits(Ty) &&
"Type size mismatch!");

if (BaseTy) {
CharUnits NonVirtualSize = Layout.getNonVirtualSize();

uint64_t AlignedNonVirtualTypeSizeInBits =
getContext().toBits(NonVirtualSize);

assert(AlignedNonVirtualTypeSizeInBits ==
getDataLayout().getTypeAllocSizeInBits(BaseTy) &&
"Type size mismatch!");
if (!Context.getLangOpts().DebuggerSupport)
assert(AlignedNonVirtualTypeSizeInBits ==
getDataLayout().getTypeAllocSizeInBits(BaseTy) &&
"Type size mismatch!");
}

// Verify that the LLVM and AST field offsets agree.
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/cpp/no_unique_address/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CXX_SOURCES := main.cpp

include Makefile.rules
67 changes: 67 additions & 0 deletions lldb/test/API/lang/cpp/no_unique_address/TestNoUniqueAddress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Test that LLDB correctly handles fields
marked with [[no_unique_address]].
"""

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class NoUniqueAddressTestCase(TestBase):
def test(self):
self.build()
lldbutil.run_to_source_breakpoint(
self, "return 0", lldb.SBFileSpec("main.cpp", False)
)

# Qualified/unqualified lookup to templates in namespace
self.expect_expr(
"b1",
result_type="basic::Foo",
result_children=[ValueCheck(name="a", type="Empty")],
)

self.expect_expr(
"b2",
result_type="bases::Foo",
result_children=[
ValueCheck(
type="bases::B", children=[ValueCheck(name="x", type="Empty")]
),
ValueCheck(
type="bases::A",
children=[
ValueCheck(name="c", type="long", value="1"),
ValueCheck(name="d", type="long", value="2"),
],
),
ValueCheck(
type="bases::C", children=[ValueCheck(name="x", type="Empty")]
),
],
)
self.expect_expr(
"b3",
result_type="bases::Bar",
result_children=[
ValueCheck(
type="bases::B", children=[ValueCheck(name="x", type="Empty")]
),
ValueCheck(
type="bases::C", children=[ValueCheck(name="x", type="Empty")]
),
ValueCheck(
type="bases::A",
children=[
ValueCheck(name="c", type="long", value="5"),
ValueCheck(name="d", type="long", value="6"),
],
),
],
)

self.expect("frame var b1")
self.expect("frame var b2")
self.expect("frame var b3")
35 changes: 35 additions & 0 deletions lldb/test/API/lang/cpp/no_unique_address/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
struct Empty {};

namespace basic {
struct Foo {
[[no_unique_address]] Empty a;
};
} // namespace basic

namespace bases {
struct A {
long c, d;
};

struct B {
[[no_unique_address]] Empty x;
};

struct C {
[[no_unique_address]] Empty x;
};

struct Foo : B, A, C {};
struct Bar : B, C, A {};
} // namespace bases

int main() {
basic::Foo b1;
bases::Foo b2;
bases::Bar b3;
b2.c = 1;
b2.d = 2;
b3.c = 5;
b3.d = 6;
return 0;
}