diff mbox

[FFmpeg-devel] avformat/wavdec: Eliminate goto for clang -O0 DCE

Message ID 20161216004457.95321-1-mark.hsj@gmail.com
State Accepted
Commit a5cf600ccb7f20b65d552fef5c5d010513fcf74c
Headers show

Commit Message

Mark Harris Dec. 16, 2016, 12:44 a.m. UTC
Clang is not able to eliminate the reference to ff_spdif_probe() when
there is a goto target in the same block and optimization is disabled.

This fixes the following build failure on OS X:
  ./configure --disable-everything --disable-doc \
    --enable-decoder=pcm_s16le --enable-demuxer=wav \
    --enable-protocol=file --disable-optimizations --cc=clang
  make
  ...
  Undefined symbols for architecture x86_64:
    "_ff_spdif_probe", referenced from:
        _set_spdif in libavformat.a(wavdec.o)
  ld: symbol(s) not found for architecture x86_64
---
 libavformat/wavdec.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

Comments

Michael Niedermayer Dec. 16, 2016, 12:22 p.m. UTC | #1
On Thu, Dec 15, 2016 at 04:44:57PM -0800, Mark Harris wrote:
> Clang is not able to eliminate the reference to ff_spdif_probe() when
> there is a goto target in the same block and optimization is disabled.
> 
> This fixes the following build failure on OS X:
>   ./configure --disable-everything --disable-doc \
>     --enable-decoder=pcm_s16le --enable-demuxer=wav \
>     --enable-protocol=file --disable-optimizations --cc=clang
>   make
>   ...
>   Undefined symbols for architecture x86_64:
>     "_ff_spdif_probe", referenced from:
>         _set_spdif in libavformat.a(wavdec.o)
>   ld: symbol(s) not found for architecture x86_64
> ---
>  libavformat/wavdec.c | 38 +++++++++++++++++---------------------
>  1 file changed, 17 insertions(+), 21 deletions(-)

applied, this code is simpler than before too

thanks

[...]
diff mbox

Patch

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 7176cd6f2d..ae42a6167f 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -64,34 +64,30 @@  static void set_spdif(AVFormatContext *s, WAVDemuxContext *wav)
 {
     if (CONFIG_SPDIF_DEMUXER && s->streams[0]->codecpar->codec_tag == 1) {
         enum AVCodecID codec;
-        uint8_t *buf = NULL;
         int len = 1<<16;
         int ret = ffio_ensure_seekback(s->pb, len);
-        int64_t pos = avio_tell(s->pb);
 
-        if (ret < 0)
-            goto end;
-
-        buf = av_malloc(len);
-        if (!buf) {
-            ret = AVERROR(ENOMEM);
-            goto end;
+        if (ret >= 0) {
+            uint8_t *buf = av_malloc(len);
+            if (!buf) {
+                ret = AVERROR(ENOMEM);
+            } else {
+                int64_t pos = avio_tell(s->pb);
+                len = ret = avio_read(s->pb, buf, len);
+                if (len >= 0) {
+                    ret = ff_spdif_probe(buf, len, &codec);
+                    if (ret > AVPROBE_SCORE_EXTENSION) {
+                        s->streams[0]->codecpar->codec_id = codec;
+                        wav->spdif = 1;
+                    }
+                }
+                avio_seek(s->pb, pos, SEEK_SET);
+                av_free(buf);
+            }
         }
 
-        len = ret = avio_read(s->pb, buf, len);
-        if (ret < 0)
-            goto end;
-
-        ret = ff_spdif_probe(buf, len, &codec);
-        if (ret > AVPROBE_SCORE_EXTENSION) {
-            s->streams[0]->codecpar->codec_id = codec;
-            wav->spdif = 1;
-        }
-end:
-        avio_seek(s->pb, pos, SEEK_SET);
         if (ret < 0)
             av_log(s, AV_LOG_WARNING, "Cannot check for SPDIF\n");
-        av_free(buf);
     }
 }