| ... | ... | @@ -67,7 +67,7 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl); |
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | __attribute__ ((format (printf, 3, 4))) |
| 70 | | static void emit_warning(Context *c, const Decl *decl, const char *format, ...) { |
| 70 | static void emit_warning(Context *c, const SourceLocation &sl, const char *format, ...) { |
| 71 | 71 | if (!c->warnings_on) { |
| 72 | 72 | return; |
| 73 | 73 | } |
| ... | ... | @@ -77,8 +77,6 @@ static void emit_warning(Context *c, const Decl *decl, const char *format, ...) |
| 77 | 77 | Buf *msg = buf_vprintf(format, ap); |
| 78 | 78 | va_end(ap); |
| 79 | 79 | |
| 80 | | SourceLocation sl = decl->getLocation(); |
| 81 | | |
| 82 | 80 | StringRef filename = c->source_manager->getFilename(sl); |
| 83 | 81 | const char *filename_bytes = (const char *)filename.bytes_begin(); |
| 84 | 82 | Buf *path; |
| ... | ... | @@ -185,14 +183,14 @@ static ConstExprValue *create_const_int_ap(Context *c, TypeTableEntry *type, con |
| 185 | 183 | { |
| 186 | 184 | if (aps_int.isSigned()) { |
| 187 | 185 | if (aps_int > INT64_MAX || aps_int < INT64_MIN) { |
| 188 | | emit_warning(c, source_decl, "integer overflow\n"); |
| 186 | emit_warning(c, source_decl->getLocation(), "integer overflow\n"); |
| 189 | 187 | return nullptr; |
| 190 | 188 | } else { |
| 191 | 189 | return create_const_signed(type, aps_int.getExtValue()); |
| 192 | 190 | } |
| 193 | 191 | } else { |
| 194 | 192 | if (aps_int > INT64_MAX) { |
| 195 | | emit_warning(c, source_decl, "integer overflow\n"); |
| 193 | emit_warning(c, source_decl->getLocation(), "integer overflow\n"); |
| 196 | 194 | return nullptr; |
| 197 | 195 | } else { |
| 198 | 196 | return create_const_unsigned_negative(type, aps_int.getExtValue(), false); |
| ... | ... | @@ -347,7 +345,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 347 | 345 | case BuiltinType::OCLClkEvent: |
| 348 | 346 | case BuiltinType::OCLQueue: |
| 349 | 347 | case BuiltinType::OCLReserveID: |
| 350 | | emit_warning(c, decl, "missed a builtin type"); |
| 348 | emit_warning(c, decl->getLocation(), "missed a builtin type"); |
| 351 | 349 | return c->codegen->builtin_types.entry_invalid; |
| 352 | 350 | } |
| 353 | 351 | break; |
| ... | ... | @@ -358,7 +356,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 358 | 356 | QualType child_qt = pointer_ty->getPointeeType(); |
| 359 | 357 | TypeTableEntry *child_type = resolve_qual_type(c, child_qt, decl); |
| 360 | 358 | if (type_is_invalid(child_type)) { |
| 361 | | emit_warning(c, decl, "pointer to unresolved type"); |
| 359 | emit_warning(c, decl->getLocation(), "pointer to unresolved type"); |
| 362 | 360 | return c->codegen->builtin_types.entry_invalid; |
| 363 | 361 | } |
| 364 | 362 | |
| ... | ... | @@ -423,7 +421,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 423 | 421 | case ETK_Class: |
| 424 | 422 | case ETK_Typename: |
| 425 | 423 | case ETK_None: |
| 426 | | emit_warning(c, decl, "unsupported elaborated type"); |
| 424 | emit_warning(c, decl->getLocation(), "unsupported elaborated type"); |
| 427 | 425 | return c->codegen->builtin_types.entry_invalid; |
| 428 | 426 | } |
| 429 | 427 | } |
| ... | ... | @@ -435,52 +433,52 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 435 | 433 | case CC_C: // __attribute__((cdecl)) |
| 436 | 434 | break; |
| 437 | 435 | case CC_X86StdCall: // __attribute__((stdcall)) |
| 438 | | emit_warning(c, decl, "function type has x86 stdcall calling convention"); |
| 436 | emit_warning(c, decl->getLocation(), "function type has x86 stdcall calling convention"); |
| 439 | 437 | return c->codegen->builtin_types.entry_invalid; |
| 440 | 438 | case CC_X86FastCall: // __attribute__((fastcall)) |
| 441 | | emit_warning(c, decl, "function type has x86 fastcall calling convention"); |
| 439 | emit_warning(c, decl->getLocation(), "function type has x86 fastcall calling convention"); |
| 442 | 440 | return c->codegen->builtin_types.entry_invalid; |
| 443 | 441 | case CC_X86ThisCall: // __attribute__((thiscall)) |
| 444 | | emit_warning(c, decl, "function type has x86 thiscall calling convention"); |
| 442 | emit_warning(c, decl->getLocation(), "function type has x86 thiscall calling convention"); |
| 445 | 443 | return c->codegen->builtin_types.entry_invalid; |
| 446 | 444 | case CC_X86VectorCall: // __attribute__((vectorcall)) |
| 447 | | emit_warning(c, decl, "function type has x86 vectorcall calling convention"); |
| 445 | emit_warning(c, decl->getLocation(), "function type has x86 vectorcall calling convention"); |
| 448 | 446 | return c->codegen->builtin_types.entry_invalid; |
| 449 | 447 | case CC_X86Pascal: // __attribute__((pascal)) |
| 450 | | emit_warning(c, decl, "function type has x86 pascal calling convention"); |
| 448 | emit_warning(c, decl->getLocation(), "function type has x86 pascal calling convention"); |
| 451 | 449 | return c->codegen->builtin_types.entry_invalid; |
| 452 | 450 | case CC_Win64: // __attribute__((ms_abi)) |
| 453 | | emit_warning(c, decl, "function type has win64 calling convention"); |
| 451 | emit_warning(c, decl->getLocation(), "function type has win64 calling convention"); |
| 454 | 452 | return c->codegen->builtin_types.entry_invalid; |
| 455 | 453 | case CC_X86_64SysV: // __attribute__((sysv_abi)) |
| 456 | | emit_warning(c, decl, "function type has x86 64sysv calling convention"); |
| 454 | emit_warning(c, decl->getLocation(), "function type has x86 64sysv calling convention"); |
| 457 | 455 | return c->codegen->builtin_types.entry_invalid; |
| 458 | 456 | case CC_X86RegCall: |
| 459 | | emit_warning(c, decl, "function type has x86 reg calling convention"); |
| 457 | emit_warning(c, decl->getLocation(), "function type has x86 reg calling convention"); |
| 460 | 458 | return c->codegen->builtin_types.entry_invalid; |
| 461 | 459 | case CC_AAPCS: // __attribute__((pcs("aapcs"))) |
| 462 | | emit_warning(c, decl, "function type has aapcs calling convention"); |
| 460 | emit_warning(c, decl->getLocation(), "function type has aapcs calling convention"); |
| 463 | 461 | return c->codegen->builtin_types.entry_invalid; |
| 464 | 462 | case CC_AAPCS_VFP: // __attribute__((pcs("aapcs-vfp"))) |
| 465 | | emit_warning(c, decl, "function type has aapcs-vfp calling convention"); |
| 463 | emit_warning(c, decl->getLocation(), "function type has aapcs-vfp calling convention"); |
| 466 | 464 | return c->codegen->builtin_types.entry_invalid; |
| 467 | 465 | case CC_IntelOclBicc: // __attribute__((intel_ocl_bicc)) |
| 468 | | emit_warning(c, decl, "function type has intel_ocl_bicc calling convention"); |
| 466 | emit_warning(c, decl->getLocation(), "function type has intel_ocl_bicc calling convention"); |
| 469 | 467 | return c->codegen->builtin_types.entry_invalid; |
| 470 | 468 | case CC_SpirFunction: // default for OpenCL functions on SPIR target |
| 471 | | emit_warning(c, decl, "function type has SPIR function calling convention"); |
| 469 | emit_warning(c, decl->getLocation(), "function type has SPIR function calling convention"); |
| 472 | 470 | return c->codegen->builtin_types.entry_invalid; |
| 473 | 471 | case CC_OpenCLKernel: |
| 474 | | emit_warning(c, decl, "function type has OpenCLKernel calling convention"); |
| 472 | emit_warning(c, decl->getLocation(), "function type has OpenCLKernel calling convention"); |
| 475 | 473 | return c->codegen->builtin_types.entry_invalid; |
| 476 | 474 | case CC_Swift: |
| 477 | | emit_warning(c, decl, "function type has Swift calling convention"); |
| 475 | emit_warning(c, decl->getLocation(), "function type has Swift calling convention"); |
| 478 | 476 | return c->codegen->builtin_types.entry_invalid; |
| 479 | 477 | case CC_PreserveMost: |
| 480 | | emit_warning(c, decl, "function type has PreserveMost calling convention"); |
| 478 | emit_warning(c, decl->getLocation(), "function type has PreserveMost calling convention"); |
| 481 | 479 | return c->codegen->builtin_types.entry_invalid; |
| 482 | 480 | case CC_PreserveAll: |
| 483 | | emit_warning(c, decl, "function type has PreserveAll calling convention"); |
| 481 | emit_warning(c, decl->getLocation(), "function type has PreserveAll calling convention"); |
| 484 | 482 | return c->codegen->builtin_types.entry_invalid; |
| 485 | 483 | } |
| 486 | 484 | |
| ... | ... | @@ -495,7 +493,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 495 | 493 | } else { |
| 496 | 494 | fn_type_id.return_type = resolve_qual_type(c, fn_proto_ty->getReturnType(), decl); |
| 497 | 495 | if (type_is_invalid(fn_type_id.return_type)) { |
| 498 | | emit_warning(c, decl, "unresolved function proto return type"); |
| 496 | emit_warning(c, decl->getLocation(), "unresolved function proto return type"); |
| 499 | 497 | return c->codegen->builtin_types.entry_invalid; |
| 500 | 498 | } |
| 501 | 499 | // convert c_void to actual void (only for return type) |
| ... | ... | @@ -510,7 +508,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 510 | 508 | TypeTableEntry *param_type = resolve_qual_type(c, qt, decl); |
| 511 | 509 | |
| 512 | 510 | if (type_is_invalid(param_type)) { |
| 513 | | emit_warning(c, decl, "unresolved function proto parameter type"); |
| 511 | emit_warning(c, decl->getLocation(), "unresolved function proto parameter type"); |
| 514 | 512 | return c->codegen->builtin_types.entry_invalid; |
| 515 | 513 | } |
| 516 | 514 | |
| ... | ... | @@ -536,7 +534,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 536 | 534 | const ConstantArrayType *const_arr_ty = static_cast<const ConstantArrayType *>(ty); |
| 537 | 535 | TypeTableEntry *child_type = resolve_qual_type(c, const_arr_ty->getElementType(), decl); |
| 538 | 536 | if (child_type->id == TypeTableEntryIdInvalid) { |
| 539 | | emit_warning(c, decl, "unresolved array element type"); |
| 537 | emit_warning(c, decl->getLocation(), "unresolved array element type"); |
| 540 | 538 | return child_type; |
| 541 | 539 | } |
| 542 | 540 | uint64_t size = const_arr_ty->getSize().getLimitedValue(); |
| ... | ... | @@ -591,7 +589,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 591 | 589 | case Type::Pipe: |
| 592 | 590 | case Type::ObjCTypeParam: |
| 593 | 591 | case Type::DeducedTemplateSpecialization: |
| 594 | | emit_warning(c, decl, "missed a '%s' type", ty->getTypeClassName()); |
| 592 | emit_warning(c, decl->getLocation(), "missed a '%s' type", ty->getTypeClassName()); |
| 595 | 593 | return c->codegen->builtin_types.entry_invalid; |
| 596 | 594 | } |
| 597 | 595 | zig_unreachable(); |
| ... | ... | @@ -823,6 +821,8 @@ static AstNode * trans_implicit_cast_expr(Context *c, ImplicitCastExpr *stmt) { |
| 823 | 821 | switch (stmt->getCastKind()) { |
| 824 | 822 | case CK_LValueToRValue: |
| 825 | 823 | return trans_expr(c, stmt->getSubExpr()); |
| 824 | case CK_IntegralCast: |
| 825 | zig_panic("TODO handle C translation cast CK_IntegralCast"); |
| 826 | 826 | case CK_Dependent: |
| 827 | 827 | zig_panic("TODO handle C translation cast CK_Dependent"); |
| 828 | 828 | case CK_BitCast: |
| ... | ... | @@ -871,8 +871,6 @@ static AstNode * trans_implicit_cast_expr(Context *c, ImplicitCastExpr *stmt) { |
| 871 | 871 | zig_panic("TODO handle C translation cast CK_ToVoid"); |
| 872 | 872 | case CK_VectorSplat: |
| 873 | 873 | zig_panic("TODO handle C translation cast CK_VectorSplat"); |
| 874 | | case CK_IntegralCast: |
| 875 | | zig_panic("TODO handle C translation cast CK_IntegralCast"); |
| 876 | 874 | case CK_IntegralToBoolean: |
| 877 | 875 | zig_panic("TODO handle C translation cast CK_IntegralToBoolean"); |
| 878 | 876 | case CK_IntegralToFloating: |
| ... | ... | @@ -1424,7 +1422,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) { |
| 1424 | 1422 | TypeTableEntry *fn_type = resolve_qual_type(c, fn_decl->getType(), fn_decl); |
| 1425 | 1423 | |
| 1426 | 1424 | if (fn_type->id == TypeTableEntryIdInvalid) { |
| 1427 | | emit_warning(c, fn_decl, "ignoring function '%s' - unable to resolve type", buf_ptr(fn_name)); |
| 1425 | emit_warning(c, fn_decl->getLocation(), "ignoring function '%s' - unable to resolve type", buf_ptr(fn_name)); |
| 1428 | 1426 | return; |
| 1429 | 1427 | } |
| 1430 | 1428 | assert(fn_type->id == TypeTableEntryIdFn); |
| ... | ... | @@ -1482,7 +1480,7 @@ static void visit_typedef_decl(Context *c, const TypedefNameDecl *typedef_decl) |
| 1482 | 1480 | |
| 1483 | 1481 | TypeTableEntry *child_type = resolve_qual_type(c, child_qt, typedef_decl); |
| 1484 | 1482 | if (child_type->id == TypeTableEntryIdInvalid) { |
| 1485 | | emit_warning(c, typedef_decl, "typedef %s - unresolved child type", buf_ptr(type_name)); |
| 1483 | emit_warning(c, typedef_decl->getLocation(), "typedef %s - unresolved child type", buf_ptr(type_name)); |
| 1486 | 1484 | return; |
| 1487 | 1485 | } |
| 1488 | 1486 | add_const_type(c, type_name, child_type); |
| ... | ... | @@ -1663,7 +1661,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 1663 | 1661 | const char *raw_name = decl_name(record_decl); |
| 1664 | 1662 | |
| 1665 | 1663 | if (!record_decl->isStruct()) { |
| 1666 | | emit_warning(c, record_decl, "skipping record %s, not a struct", raw_name); |
| 1664 | emit_warning(c, record_decl->getLocation(), "skipping record %s, not a struct", raw_name); |
| 1667 | 1665 | return c->codegen->builtin_types.entry_invalid; |
| 1668 | 1666 | } |
| 1669 | 1667 | |
| ... | ... | @@ -1702,7 +1700,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 1702 | 1700 | const FieldDecl *field_decl = *it; |
| 1703 | 1701 | |
| 1704 | 1702 | if (field_decl->isBitField()) { |
| 1705 | | emit_warning(c, field_decl, "struct %s demoted to opaque type - has bitfield\n", buf_ptr(bare_name)); |
| 1703 | emit_warning(c, field_decl->getLocation(), "struct %s demoted to opaque type - has bitfield\n", buf_ptr(bare_name)); |
| 1706 | 1704 | replace_with_fwd_decl(c, struct_type, full_type_name); |
| 1707 | 1705 | return struct_type; |
| 1708 | 1706 | } |
| ... | ... | @@ -1729,7 +1727,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 1729 | 1727 | type_struct_field->type_entry = field_type; |
| 1730 | 1728 | |
| 1731 | 1729 | if (type_is_invalid(field_type) || !type_is_complete(field_type)) { |
| 1732 | | emit_warning(c, field_decl, "struct %s demoted to opaque type - unresolved type\n", buf_ptr(bare_name)); |
| 1730 | emit_warning(c, field_decl->getLocation(), "struct %s demoted to opaque type - unresolved type\n", buf_ptr(bare_name)); |
| 1733 | 1731 | replace_with_fwd_decl(c, struct_type, full_type_name); |
| 1734 | 1732 | return struct_type; |
| 1735 | 1733 | } |
| ... | ... | @@ -1810,17 +1808,17 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) { |
| 1810 | 1808 | case VarDecl::TLS_None: |
| 1811 | 1809 | break; |
| 1812 | 1810 | case VarDecl::TLS_Static: |
| 1813 | | emit_warning(c, var_decl, "ignoring variable '%s' - static thread local storage\n", buf_ptr(name)); |
| 1811 | emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - static thread local storage\n", buf_ptr(name)); |
| 1814 | 1812 | return; |
| 1815 | 1813 | case VarDecl::TLS_Dynamic: |
| 1816 | | emit_warning(c, var_decl, "ignoring variable '%s' - dynamic thread local storage\n", buf_ptr(name)); |
| 1814 | emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - dynamic thread local storage\n", buf_ptr(name)); |
| 1817 | 1815 | return; |
| 1818 | 1816 | } |
| 1819 | 1817 | |
| 1820 | 1818 | QualType qt = var_decl->getType(); |
| 1821 | 1819 | TypeTableEntry *var_type = resolve_qual_type(c, qt, var_decl); |
| 1822 | 1820 | if (var_type->id == TypeTableEntryIdInvalid) { |
| 1823 | | emit_warning(c, var_decl, "ignoring variable '%s' - unresolved type\n", buf_ptr(name)); |
| 1821 | emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - unresolved type\n", buf_ptr(name)); |
| 1824 | 1822 | return; |
| 1825 | 1823 | } |
| 1826 | 1824 | |
| ... | ... | @@ -1830,12 +1828,12 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) { |
| 1830 | 1828 | |
| 1831 | 1829 | if (is_static && !is_extern) { |
| 1832 | 1830 | if (!var_decl->hasInit()) { |
| 1833 | | emit_warning(c, var_decl, "ignoring variable '%s' - no initializer\n", buf_ptr(name)); |
| 1831 | emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - no initializer\n", buf_ptr(name)); |
| 1834 | 1832 | return; |
| 1835 | 1833 | } |
| 1836 | 1834 | APValue *ap_value = var_decl->evaluateValue(); |
| 1837 | 1835 | if (!ap_value) { |
| 1838 | | emit_warning(c, var_decl, "ignoring variable '%s' - unable to evaluate initializer\n", buf_ptr(name)); |
| 1836 | emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - unable to evaluate initializer\n", buf_ptr(name)); |
| 1839 | 1837 | return; |
| 1840 | 1838 | } |
| 1841 | 1839 | ConstExprValue *init_value = nullptr; |
| ... | ... | @@ -1843,7 +1841,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) { |
| 1843 | 1841 | case APValue::Int: |
| 1844 | 1842 | { |
| 1845 | 1843 | if (var_type->id != TypeTableEntryIdInt) { |
| 1846 | | emit_warning(c, var_decl, |
| 1844 | emit_warning(c, var_decl->getLocation(), |
| 1847 | 1845 | "ignoring variable '%s' - int initializer for non int type\n", buf_ptr(name)); |
| 1848 | 1846 | return; |
| 1849 | 1847 | } |
| ... | ... | @@ -1864,7 +1862,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) { |
| 1864 | 1862 | case APValue::Union: |
| 1865 | 1863 | case APValue::MemberPointer: |
| 1866 | 1864 | case APValue::AddrLabelDiff: |
| 1867 | | emit_warning(c, var_decl, |
| 1865 | emit_warning(c, var_decl->getLocation(), |
| 1868 | 1866 | "ignoring variable '%s' - unrecognized initializer value kind\n", buf_ptr(name)); |
| 1869 | 1867 | return; |
| 1870 | 1868 | } |
| ... | ... | @@ -1881,7 +1879,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) { |
| 1881 | 1879 | return; |
| 1882 | 1880 | } |
| 1883 | 1881 | |
| 1884 | | emit_warning(c, var_decl, "ignoring variable '%s' - non-extern, non-static variable\n", buf_ptr(name)); |
| 1882 | emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - non-extern, non-static variable\n", buf_ptr(name)); |
| 1885 | 1883 | return; |
| 1886 | 1884 | } |
| 1887 | 1885 | |
| ... | ... | @@ -1905,7 +1903,7 @@ static bool decl_visitor(void *context, const Decl *decl) { |
| 1905 | 1903 | visit_var_decl(c, static_cast<const VarDecl *>(decl)); |
| 1906 | 1904 | break; |
| 1907 | 1905 | default: |
| 1908 | | emit_warning(c, decl, "ignoring %s decl\n", decl->getDeclKindName()); |
| 1906 | emit_warning(c, decl->getLocation(), "ignoring %s decl\n", decl->getDeclKindName()); |
| 1909 | 1907 | } |
| 1910 | 1908 | |
| 1911 | 1909 | return true; |