// Limited debug info should only remove struct definitions that can
// safely be replaced by a forward declaration in the source code.
if (DebugKind <= CodeGenOptions::LimitedDebugInfo && Declaration &&
- !RD->isCompleteDefinitionRequired()) {
+ !RD->isCompleteDefinitionRequired() && CGM.getLangOpts().CPlusPlus) {
// FIXME: This implementation is problematic; there are some test
// cases where we violate the above principle, such as
// test/CodeGen/debug-info-records.c .
void CGDebugInfo::completeFwdDecl(const RecordDecl &RD) {
// In limited debug info we only want to do this if the complete type was
// required.
- if (DebugKind <= CodeGenOptions::LimitedDebugInfo)
+ if (DebugKind <= CodeGenOptions::LimitedDebugInfo &&
+ CGM.getLangOpts().CPlusPlus)
return;
QualType QTy = CGM.getContext().getRecordType(&RD);
--- /dev/null
+// RUN: %clang -flimit-debug-info -emit-llvm -g -S %s -o - | FileCheck %s
+
+// Ensure we emit the full definition of 'foo' even though only its declaration
+// is needed, since C has no ODR to ensure that the definition will be the same
+// in whatever TU actually uses/requires the definition of 'foo'.
+// CHECK: ; [ DW_TAG_structure_type ] [foo] {{.*}} [def]
+
+struct foo {
+};
+
+struct foo *f;
-// RUN: %clang -emit-llvm -g -S %s -o - | FileCheck %s
+// RUN: %clang -flimit-debug-info -emit-llvm -g -S %s -o - | FileCheck %s
-// TAG_member is used to encode debug info for 'z' in A.
-// CHECK: TAG_member
+// CHECK: ; [ DW_TAG_class_type ] [A] {{.*}} [def]
class A {
public:
int z;
}
// Verify that we're not emitting a full definition of B in limit debug mode.
-// RUN: %clang -emit-llvm -g -flimit-debug-info -S %s -o - | FileCheck %s
-// CHECK-NOT: TAG_member
+// CHECK: ; [ DW_TAG_class_type ] [B] {{.*}} [decl]
class B {
public: