# HG changeset patch # User goetz # Date 1444401577 -7200 # Node ID ad1cd9269bd453e9eb3d5458f9bef8777ac5e269 # Parent 450d454670a7e7f0e0c73007d6ddc7143e4423b0 8139116: Fixes for warning "format not a string literal" Reviewed-by: ddmitriev, david, simonis diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/classfile/classFileParser.cpp --- a/hotspot/src/share/vm/classfile/classFileParser.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/classfile/classFileParser.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -315,6 +315,7 @@ return NULL; } +#ifdef ASSERT PRAGMA_DIAG_PUSH PRAGMA_FORMAT_NONLITERAL_IGNORED void ClassFileParser::report_assert_property_failure(const char* msg, TRAPS) { @@ -327,6 +328,7 @@ fatal(msg, index, _class_name->as_C_string()); } PRAGMA_DIAG_POP +#endif constantPoolHandle ClassFileParser::parse_constant_pool(TRAPS) { ClassFileStream* cfs = stream(); diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/classfile/classFileParser.hpp --- a/hotspot/src/share/vm/classfile/classFileParser.hpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/classfile/classFileParser.hpp Fri Oct 09 16:39:37 2015 +0200 @@ -319,8 +319,8 @@ if (!b) { classfile_parse_error(msg, CHECK); } } - void report_assert_property_failure(const char* msg, TRAPS); - void report_assert_property_failure(const char* msg, int index, TRAPS); + void report_assert_property_failure(const char* msg, TRAPS) PRODUCT_RETURN; + void report_assert_property_failure(const char* msg, int index, TRAPS) PRODUCT_RETURN; inline void assert_property(bool b, const char* msg, TRAPS) { #ifdef ASSERT diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/classfile/systemDictionary.cpp --- a/hotspot/src/share/vm/classfile/systemDictionary.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -1967,7 +1967,8 @@ instanceKlassHandle k, Handle class_loader, bool defining, TRAPS) { - const char *linkage_error = NULL; + const char *linkage_error1 = NULL; + const char *linkage_error2 = NULL; { Symbol* name = k->name(); ClassLoaderData *loader_data = class_loader_data(class_loader); @@ -1984,8 +1985,8 @@ assert(check->oop_is_instance(), "noninstance in systemdictionary"); if ((defining == true) || (k() != check)) { - linkage_error = "loader (instance of %s): attempted duplicate class " - "definition for name: \"%s\""; + linkage_error1 = "loader (instance of "; + linkage_error2 = "): attempted duplicate class definition for name: \""; } else { return; } @@ -1996,10 +1997,10 @@ assert(ph_check == NULL || ph_check == name, "invalid symbol"); #endif - if (linkage_error == NULL) { + if (linkage_error1 == NULL) { if (constraints()->check_or_update(k, class_loader, name) == false) { - linkage_error = "loader constraint violation: loader (instance of %s)" - " previously initiated loading for a different type with name \"%s\""; + linkage_error1 = "loader constraint violation: loader (instance of "; + linkage_error2 = ") previously initiated loading for a different type with name \""; } } } @@ -2007,14 +2008,14 @@ // Throw error now if needed (cannot throw while holding // SystemDictionary_lock because of rank ordering) - if (linkage_error) { + if (linkage_error1) { ResourceMark rm(THREAD); const char* class_loader_name = loader_name(class_loader()); char* type_name = k->name()->as_C_string(); - size_t buflen = strlen(linkage_error) + strlen(class_loader_name) + - strlen(type_name); + size_t buflen = strlen(linkage_error1) + strlen(class_loader_name) + + strlen(linkage_error2) + strlen(type_name) + 2; // +2 for '"' and null byte. char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); - jio_snprintf(buf, buflen, linkage_error, class_loader_name, type_name); + jio_snprintf(buf, buflen, "%s%s%s%s\"", linkage_error1, class_loader_name, linkage_error2, type_name); THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); } } diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/interpreter/bytecodeTracer.cpp --- a/hotspot/src/share/vm/interpreter/bytecodeTracer.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/interpreter/bytecodeTracer.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -390,7 +390,6 @@ } -PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL void BytecodePrinter::print_attributes(int bci, outputStream* st) { // Show attributes of pre-rewritten codes Bytecodes::Code code = Bytecodes::java_code(raw_code()); @@ -512,15 +511,11 @@ } st->print(" %d " INT32_FORMAT " " INT32_FORMAT " ", default_dest, lo, hi); - int first = true; - for (int ll = lo; ll <= hi; ll++, first = false) { + const char *comma = ""; + for (int ll = lo; ll <= hi; ll++) { int idx = ll - lo; - const char *format = first ? " %d:" INT32_FORMAT " (delta: %d)" : - ", %d:" INT32_FORMAT " (delta: %d)"; -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL - st->print(format, ll, dest[idx], dest[idx]-bci); -PRAGMA_DIAG_POP + st->print("%s %d:" INT32_FORMAT " (delta: %d)", comma, ll, dest[idx], dest[idx]-bci); + comma = ","; } st->cr(); } @@ -536,14 +531,10 @@ dest[i] = bci + get_int(); }; st->print(" %d %d ", default_dest, len); - bool first = true; - for (int ll = 0; ll < len; ll++, first = false) { - const char *format = first ? " " INT32_FORMAT ":" INT32_FORMAT : - ", " INT32_FORMAT ":" INT32_FORMAT ; -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL - st->print(format, key[ll], dest[ll]); -PRAGMA_DIAG_POP + const char *comma = ""; + for (int ll = 0; ll < len; ll++) { + st->print("%s " INT32_FORMAT ":" INT32_FORMAT, comma, key[ll], dest[ll]); + comma = ","; } st->cr(); } diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/memory/heapInspection.cpp --- a/hotspot/src/share/vm/memory/heapInspection.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/memory/heapInspection.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -286,7 +286,6 @@ return true; } -PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL void KlassInfoHisto::print_title(outputStream* st, bool csv_format, bool selected[], int width_table[], const char *name_table[]) { @@ -298,11 +297,10 @@ st->print(",ClassName"); } else { st->print("Index Super"); - for (int c=0; cprint(str_fmt(width_table[c]), name_table[c]);} -PRAGMA_DIAG_POP + for (int c = 0; c < KlassSizeStats::_num_columns; c++) { + if (selected[c]) { + st->print("%*s", width_table[c], name_table[c]); + } } st->print(" ClassName"); } @@ -607,18 +605,12 @@ case KlassSizeStats::_index_inst_size: case KlassSizeStats::_index_inst_count: case KlassSizeStats::_index_method_count: -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL - st->print(str_fmt(width_table[c]), "-"); -PRAGMA_DIAG_POP + st->print("%*s", width_table[c], "-"); break; default: { double perc = (double)(100) * (double)(colsum_table[c]) / (double)sz_sum._total_bytes; -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL - st->print(perc_fmt(width_table[c]), perc); -PRAGMA_DIAG_POP + st->print("%*.1f%%", width_table[c]-1, perc); } } } diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/memory/heapInspection.hpp --- a/hotspot/src/share/vm/memory/heapInspection.hpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/memory/heapInspection.hpp Fri Oct 09 16:39:37 2015 +0200 @@ -313,32 +313,13 @@ return HeapWordSize * x->size(); } - // returns a format string to print a julong with the given width. E.g, - // printf(num_fmt(6), julong(10)) would print out the number 10 with 4 - // leading spaces. -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED - static void print_julong(outputStream* st, int width, julong n) { int num_spaces = width - julong_width(n); if (num_spaces > 0) { - st->print(str_fmt(num_spaces), ""); + st->print("%*s", num_spaces, ""); } st->print(JULONG_FORMAT, n); } -PRAGMA_DIAG_POP - - static char* perc_fmt(int width) { - static char buf[32]; - jio_snprintf(buf, sizeof(buf), "%%%d.1f%%%%", width-1); - return buf; - } - - static char* str_fmt(int width) { - static char buf[32]; - jio_snprintf(buf, sizeof(buf), "%%%ds", width); - return buf; - } static int julong_width(julong n) { if (n == 0) { diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp --- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -1892,7 +1892,7 @@ } u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray, - byte_i_ref, "mapped old type_index=%d", THREAD); + byte_i_ref, "type_index", THREAD); u2 num_element_value_pairs = Bytes::get_Java_u2((address) annotations_typeArray->adr_at(byte_i_ref)); @@ -1915,7 +1915,7 @@ u2 element_name_index = rewrite_cp_ref_in_annotation_data( annotations_typeArray, byte_i_ref, - "mapped old element_name_index=%d", THREAD); + "element_name_index", THREAD); RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("element_name_index=%d", element_name_index)); @@ -1939,8 +1939,6 @@ // annotations_typeArray if needed. Returns the original constant // pool reference if a rewrite was not needed or the new constant // pool reference if a rewrite was needed. -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data( AnnotationArray* annotations_typeArray, int &byte_i_ref, const char * trace_mesg, TRAPS) { @@ -1950,14 +1948,13 @@ u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr); u2 new_cp_index = find_new_index(old_cp_index); if (new_cp_index != 0) { - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index)); + RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("mapped old %s=%d", trace_mesg, old_cp_index)); Bytes::put_Java_u2(cp_index_addr, new_cp_index); old_cp_index = new_cp_index; } byte_i_ref += 2; return old_cp_index; } -PRAGMA_DIAG_POP // Rewrite constant pool references in the element_value portion of an @@ -2022,7 +2019,7 @@ u2 const_value_index = rewrite_cp_ref_in_annotation_data( annotations_typeArray, byte_i_ref, - "mapped old const_value_index=%d", THREAD); + "const_value_index", THREAD); RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("const_value_index=%d", const_value_index)); @@ -2041,11 +2038,11 @@ u2 type_name_index = rewrite_cp_ref_in_annotation_data( annotations_typeArray, byte_i_ref, - "mapped old type_name_index=%d", THREAD); + "type_name_index", THREAD); u2 const_name_index = rewrite_cp_ref_in_annotation_data( annotations_typeArray, byte_i_ref, - "mapped old const_name_index=%d", THREAD); + "const_name_index", THREAD); RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("type_name_index=%d const_name_index=%d", type_name_index, @@ -2065,7 +2062,7 @@ u2 class_info_index = rewrite_cp_ref_in_annotation_data( annotations_typeArray, byte_i_ref, - "mapped old class_info_index=%d", THREAD); + "class_info_index", THREAD); RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("class_info_index=%d", class_info_index)); diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/runtime/compilationPolicy.cpp --- a/hotspot/src/share/vm/runtime/compilationPolicy.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/runtime/compilationPolicy.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -416,7 +416,6 @@ } #ifndef PRODUCT -PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL void NonTieredCompPolicy::trace_frequency_counter_overflow(const methodHandle& m, int branch_bci, int bci) { if (TraceInvocationCounterOverflow) { MethodCounters* mcs = m->method_counters(); @@ -424,14 +423,11 @@ InvocationCounter* ic = mcs->invocation_counter(); InvocationCounter* bc = mcs->backedge_counter(); ResourceMark rm; - const char* msg = - bci == InvocationEntryBci - ? "comp-policy cntr ovfl @ %d in entry of " - : "comp-policy cntr ovfl @ %d in loop of "; -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL - tty->print(msg, bci); -PRAGMA_DIAG_POP + if (bci == InvocationEntryBci) { + tty->print("comp-policy cntr ovfl @ %d in entry of ", bci); + } else { + tty->print("comp-policy cntr ovfl @ %d in loop of ", bci); + } m->print_value(); tty->cr(); ic->print(); diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/runtime/globals.cpp --- a/hotspot/src/share/vm/runtime/globals.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/runtime/globals.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -349,11 +349,6 @@ return is_manageable() || is_external_ext(); } - -// Length of format string (e.g. "%.1234s") for printing ccstr below -#define FORMAT_BUFFER_LEN 16 - -PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL void Flag::print_on(outputStream* st, bool withComments, bool printRanges) { // Don't print notproduct and develop flags in a product build. if (is_constant_in_binary()) { @@ -385,14 +380,8 @@ if (cp != NULL) { const char* eol; while ((eol = strchr(cp, '\n')) != NULL) { - char format_buffer[FORMAT_BUFFER_LEN]; size_t llen = pointer_delta(eol, cp, sizeof(char)); - jio_snprintf(format_buffer, FORMAT_BUFFER_LEN, - "%%." SIZE_FORMAT "s", llen); - PRAGMA_DIAG_PUSH - PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL - st->print(format_buffer, cp); - PRAGMA_DIAG_POP + st->print("%.*s", (int)llen, cp); st->cr(); cp = eol+1; st->print("%5s %-35s += ", "", _name); diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/runtime/os.cpp --- a/hotspot/src/share/vm/runtime/os.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/runtime/os.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -96,8 +96,7 @@ // Output will be of the form "YYYY-MM-DDThh:mm:ss.mmm+zzzz\0" // 1 2 // 12345678901234567890123456789 - static const char* iso8601_format = - "%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d%02d"; + // format string: "%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d%02d" static const size_t needed_buffer = 29; // Sanity check the arguments @@ -158,7 +157,8 @@ // Print an ISO 8601 date and time stamp into the buffer const int year = 1900 + time_struct.tm_year; const int month = 1 + time_struct.tm_mon; - const int printed = jio_snprintf(buffer, buffer_length, iso8601_format, + const int printed = jio_snprintf(buffer, buffer_length, + "%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d%02d", year, month, time_struct.tm_mday, diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/services/heapDumper.cpp --- a/hotspot/src/share/vm/services/heapDumper.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/services/heapDumper.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -1848,7 +1848,6 @@ } // dump the heap to given path. -PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL int HeapDumper::dump(const char* path) { assert(path != NULL && strlen(path) > 0, "path missing"); @@ -1886,13 +1885,8 @@ if (print_to_tty()) { timer()->stop(); if (error() == NULL) { - char msg[256]; - sprintf(msg, "Heap dump file created [%s bytes in %3.3f secs]", - JLONG_FORMAT, timer()->seconds()); -PRAGMA_DIAG_PUSH -PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL - tty->print_cr(msg, writer.bytes_written()); -PRAGMA_DIAG_POP + tty->print_cr("Heap dump file created [" JLONG_FORMAT " bytes in %3.3f secs]", + writer.bytes_written(), timer()->seconds()); } else { tty->print_cr("Dump file is incomplete: %s", writer.error()); } diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/services/writeableFlags.cpp --- a/hotspot/src/share/vm/services/writeableFlags.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/services/writeableFlags.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -57,7 +57,6 @@ } } -PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL static void print_flag_error_message_if_needed(Flag::Error error, const char* name, FormatBuffer<80>& err_msg) { if (error == Flag::SUCCESS) { return; diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp --- a/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp Fri Oct 09 16:39:37 2015 +0200 @@ -287,8 +287,6 @@ // Tested to work with clang version 3.1 and better. #define PRAGMA_DIAG_PUSH _Pragma("GCC diagnostic push") #define PRAGMA_DIAG_POP _Pragma("GCC diagnostic pop") -#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL -#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED // Hack to deal with gcc yammering about non-security format stuff #else @@ -297,8 +295,6 @@ // versions of the macro-pragma to obtain better checking with newer compilers. #define PRAGMA_DIAG_PUSH #define PRAGMA_DIAG_POP -#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED -#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL #endif #if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95) diff -r 450d454670a7 -r ad1cd9269bd4 hotspot/src/share/vm/utilities/xmlstream.cpp --- a/hotspot/src/share/vm/utilities/xmlstream.cpp Mon Oct 26 20:07:50 2015 +0100 +++ b/hotspot/src/share/vm/utilities/xmlstream.cpp Fri Oct 09 16:39:37 2015 +0200 @@ -340,6 +340,7 @@ print_raw_cr(">"); } +// If you remove the PRAGMA, this fails to compile with clang-503.0.40. PRAGMA_DIAG_PUSH PRAGMA_FORMAT_NONLITERAL_IGNORED // ------------------------------------------------------------------